BelongsTo("app\\common\\model\\store\\Store", 'store_id', 'store_id'); } /** * 关联店员表 */ public function clerk() { return $this->BelongsTo("app\\common\\model\\store\\Clerk", 'clerk_id', 'clerk_id'); } /** * 关联订单表 */ public function order() { return $this->BelongsTo("app\\common\\model\\order\\Order", 'order_id', 'order_id'); } /** * 关联供应商表 */ public function supplier() { return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id')->field(['shop_supplier_id', 'name']); } /** * 订单类型 * @param $value * @return array */ public function getOrderTypeAttr($value) { $types = OrderTypeEnum::getTypeName(); return ['text' => $types[$value], 'value' => $value]; } /** * 新增核销记录 */ public static function add( $order_id, $store_id, $clerk_id, $shop_supplier_id, $order_type = OrderTypeEnum::MASTER, $commission, $delivery_fee ) { return (new static)->save([ 'order_id' => $order_id, 'order_type' => $order_type, 'store_id' => $store_id, 'clerk_id' => $clerk_id, 'shop_supplier_id' => $shop_supplier_id, 'commission'=>$commission, 'delivery_fee'=>$delivery_fee, 'app_id' => self::$app_id ]); } /** * 核销订单详情 */ public static function detail($where) { $filter = is_array($where) ? $where : ['order_id' => $where]; return (new static())->where($filter)->find(); } /** * 获取队长订单列表 */ public function getSettled($store_id, $clerk_id = -1) { $model = $this; if($clerk_id>0){ //只查门店配送的订单 $model=$model->where('clerk_id', '=', $clerk_id)->where('delivery_fee','>=','0.01'); } $data = $model->with(['store']) ->where('store_id', '=', $store_id) ->order(['create_time' => 'desc']) ->paginate(15); if ($data->isEmpty()) { return $data; } // 整理订单信息 $with = ['product' => ['image', 'refund'], 'address', 'user']; return OrderService::getOrderList($data, 'order_master', $with); } }