| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\common\model\order;
- use app\common\model\BaseModel;
- /**
- * 订单商品模型
- */
- class OrderProduct extends BaseModel
- {
- protected $name = 'order_product';
- protected $pk = 'order_product_id';
- /**
- * 订单商品列表
- * @return \think\model\relation\BelongsTo
- */
- public function image()
- {
- return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id');
- }
- /**
- * 关联商品表
- * @return \think\model\relation\BelongsTo
- */
- public function product()
- {
- return $this->belongsTo('app\\common\\model\\product\\Product');
- }
- /**
- * 关联商品sku表
- * @return \think\model\relation\BelongsTo
- */
- public function sku()
- {
- return $this->belongsTo('app\\common\\model\\product\\ProductSku', 'spec_sku_id', 'spec_sku_id');
- }
- /**
- * 关联订单主表
- * @return \think\model\relation\BelongsTo
- */
- public function orderM()
- {
- return $this->belongsTo('Order','order_id','order_id');
- }
- /**
- * 售后单记录表
- * @return \think\model\relation\HasOne
- */
- public function refund()
- {
- return $this->hasOne('app\\common\\model\\order\\OrderRefund');
- }
- /**
- * 关联分销商
- * @return \think\model\relation\BelongsTo
- */
- public function agent()
- {
- return $this->belongsTo('app\\common\\model\\agent\\Apply', 'agent_user_id', 'user_id');
- }
- /**
- * 订单商品详情
- */
- public static function detail($where)
- {
- return (new static())->with(['image', 'refund', 'orderM'])->find($where);
- }
- /**
- * 获取商品数据 (可指定某天)
- */
- public function getProductData($startDate = null, $endDate = null, $type, $shop_supplier_id)
- {
- $model = $this;
- if($shop_supplier_id > 0){
- $model = $model->where('order.shop_supplier_id', '=', $shop_supplier_id);
- }
- $model = $model->alias('order_product')
- ->join('order order', 'order_product.order_id = order.order_id','left');
- $model = $model->where('order.create_time', '>=', strtotime($startDate));
- if(is_null($endDate)){
- $model = $model->where('order.create_time', '<', strtotime($startDate) + 86400);
- }else{
- $model = $model->where('order.create_time', '<', strtotime($endDate) + 86400);
- }
- if($type == 'no_pay'){
- // 未支付
- return $model->where('order.pay_status', '=', 10)->sum('order_product.total_num');
- }else if($type == 'pay'){
- // 已支付
- return $model->where('order.pay_status', '=', 20)->sum('order_product.total_num');
- }
- return 0;
- }
- }
|