123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\model\order;
- use app\model\activity\combination\StorePink;
- use app\model\product\sku\StoreProductVirtual;
- use app\model\store\DeliveryService;
- use app\model\store\SystemStore;
- use app\model\store\SystemStoreStaff;
- use app\model\supplier\SystemSupplier;
- use app\model\user\User;
- use app\model\user\UserBrokerage;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use think\Model;
- /**
- * 订单Model
- * Class StoreOrder
- * @package app\model\order
- */
- class StoreOrder extends BaseModel
- {
- use ModelTrait;
- /**
- * 支付类型
- * @var string[]
- */
- protected $pay_type = [
- 1 => 'weixin',
- 2 => 'yue',
- 3 => 'offline',
- 4 => 'alipay'
- ];
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'store_order';
- protected $insert = ['add_time'];
- /**
- * 更新时间
- * @var bool | string | int
- */
- protected $updateTime = false;
- /**
- * 创建时间修改器
- * @return int
- */
- protected function setAddTimeAttr($time = 0)
- {
- if ($time) return $time;
- return time();
- }
- /**
- * 自定义表单信息
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function setCustomFormAttr($value)
- {
- if ($value) {
- return is_array($value) ? json_encode($value) : $value;
- }
- return '';
- }
- /**
- * 自定义表单信息
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function getCustomFormAttr($value)
- {
- if ($value) {
- return is_string($value) ? json_decode($value, true) : $value;
- }
- return [];
- }
- /**
- * 优惠活动赠送信息
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function getPromotionsGiveAttr($value)
- {
- if ($value) {
- return is_string($value) ? json_decode($value, true) : $value;
- }
- return [];
- }
- /**
- * 优惠活动赠送优惠券
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function getGiveCouponAttr($value)
- {
- if ($value) {
- return is_string($value) ? explode(',', $value) : $value;
- }
- return [];
- }
- /**
- * 一对多关联查询子订单
- * @return \think\model\relation\HasMany
- */
- public function split()
- {
- return $this->hasMany(StoreOrder::class, 'pid', 'id');
- }
- /**
- * 一对一关联用户表
- * @return \think\model\relation\HasOne
- */
- public function user()
- {
- return $this->hasOne(User::class, 'uid', 'uid', false)->field(['uid', 'avatar', 'nickname', 'phone', 'now_money', 'integral', 'delete_time'])->bind([
- 'avatar' => 'avatar',
- 'nickname' => 'nickname',
- 'phone' => 'phone',
- 'now_money' => 'now_money',
- 'integral' => 'integral',
- 'delete_time' => 'delete_time'
- ]);
- }
- /**
- * 一对多关联退款订单
- * @return \think\model\relation\hasMany
- */
- public function refund()
- {
- return $this->hasMany(StoreOrderRefund::class, 'store_order_id', 'id')->where('refund_type', '<>', 3)->where('is_cancel', 0);
- }
- /**
- * 一对多关联订单优惠详情
- * @return \think\model\relation\hasMany
- */
- public function promotions()
- {
- return $this->hasMany(StoreOrderPromotions::class, 'oid', 'id');
- }
- /**
- * 一对一关联上级用户信息
- * @return \think\model\relation\HasOne
- */
- public function spread()
- {
- return $this->hasOne(User::class, 'uid', 'spread_uid')->field(['uid', 'nickname'])->bind([
- 'spread_nickname' => 'nickname'
- ]);
- }
- /**
- * 一对一拼团获取状态
- * @return \think\model\relation\HasOne
- */
- public function pink()
- {
- return $this->hasOne(StorePink::class, 'id', 'pink_id')->field(['id', 'order_id_key', 'status'])->bind([
- 'pinkStatus' => 'status'
- ]);
- }
- /**
- * 门店一对一关联
- * @return \think\model\relation\HasOne
- */
- public function store()
- {
- return $this->hasOne(SystemStore::class, 'id', 'store_id')->hidden(['bank_code,bank_address', 'alipay_account', 'alipay_qrcode_url', 'wechat', 'wechat_qrcode_url']);
- }
- /**
- * 订单关联门店店员
- * @return \think\model\relation\HasOne
- */
- public function storeStaff()
- {
- return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->field(['id', 'uid', 'store_id', 'staff_name'])->bind([
- 'staff_uid' => 'uid',
- 'staff_store_id' => 'store_id',
- 'clerk_name' => 'staff_name'
- ]);
- }
- /**
- * 订单关联店员
- * @return \think\model\relation\HasOne
- */
- public function staff()
- {
- return $this->hasOne(SystemStoreStaff::class, 'uid', 'clerk_id')->field(['id', 'uid', 'store_id', 'staff_name'])->bind([
- 'staff_uid' => 'uid',
- 'staff_store_id' => 'store_id',
- 'clerk_name' => 'staff_name'
- ]);
- }
- /**
- * 店员关联用户
- * @return \think\model\relation\HasOne
- */
- public function staffUser()
- {
- return $this->hasOne(User::class, 'uid', 'staff_uid')->field(['uid', 'nickname'])->bind([
- 'clerk_name' => 'nickname'
- ]);
- }
- /**
- * 关联配送员
- * @return \think\model\relation\HasOne
- */
- public function deliveryService()
- {
- return $this->hasOne(DeliveryService::class, 'uid', 'delivery_uid')->field(['uid', 'nickname'])->bind([
- 'delivery_name' => 'nickname'
- ]);
- }
- /**
- * 关联订单发票
- * @return \think\model\relation\HasOne
- */
- public function invoice()
- {
- return $this->hasOne(StoreOrderInvoice::class, 'order_id', 'id');
- }
- /**
- * 关联分佣表
- * @return \think\model\relation\HasOne
- */
- public function brokerage()
- {
- return $this->hasOne(UserBrokerage::class, 'link_id', 'id');
- }
- /**
- * 关联卡密
- * @return \think\model\relation\HasMany
- */
- public function virtual()
- {
- return $this->hasMany(StoreProductVirtual::class, 'order_id', 'order_id')->where('order_type', 1);
- }
- /**
- * 关联订单记录
- * @return \think\model\relation\HasMany
- */
- public function orderStatus()
- {
- return $this->hasMany(StoreOrderStatus::class, 'oid', 'id');
- }
- /**
- * 关联配送订单记录
- * @return \think\model\relation\hasOne
- */
- public function deliveryOrder()
- {
- return $this->hasOne(StoreDeliveryOrder::class, 'oid', 'id');
- }
- /**
- * 购物车ID修改器
- * @param $value
- * @return false|string
- */
- protected function setCartIdAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
- /**
- * 购物车获取器
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function getCartIdAttr($value, $data)
- {
- return $value ? json_decode($value, true) : [];
- }
- /**
- * 订单ID搜索器
- * @param Model $query
- * @param $value
- */
- public function searchOrderIdAttr($query, $value)
- {
- $query->where('order_id', $value);
- }
- /**
- * 活动ID搜索器
- * @param Model $query
- * @param $value
- */
- public function searchActivityIdAttr($query, $value)
- {
- if ($value !== '') $query->where('activity_id', $value);
- }
- /**
- * 父类ID搜索器
- * @param Model $query
- * @param $value
- */
- public function searchPidAttr($query, $value)
- {
- if ($value === 0) {
- $query->where('pid', '>=', 0);
- } else {
- if (is_array($value)) {
- $query->whereIn('pid', $value);
- } else {
- $query->where('pid', $value);
- }
- }
- }
- /**
- * 没拆分订单 与子订单(0:为拆分订单-1:已拆分主订单 >0 :拆分后子订单)
- * @param Model $query
- * @param $value
- */
- public function searchNotPidAttr($query, $value)
- {
- $query->where('pid', '<>', -1);
- }
- /**
- * @param Model $query
- * @param $value
- */
- public function searchIdAttr($query, $value)
- {
- if (is_array($value)) {
- $query->whereIn('id', $value);
- } else {
- $query->where('id', $value);
- }
- }
- /**
- * 支付方式搜索器
- * @param $query
- * @param $value
- */
- public function searchPayTypeAttr($query, $value)
- {
- if (is_array($value)) {
- $query->whereIn('pay_type', $value);
- } else {
- if ($value !== '') {
- $pay_type = $this->pay_type;
- if (in_array($value, array_keys($pay_type)) && $type = $pay_type[$value] ?? '') {
- $query->where('pay_type', $type);
- } else {
- $query->where('pay_type', $value);
- }
- }
- }
- }
- /**
- * 不等于余额支付
- * @param $query
- * @param $value
- */
- public function searchPayTypeNoAttr($query, $value)
- {
- $query->where('pay_type', "<>", $value);
- }
- /**
- * 订单id或者用户名搜索器
- * @param $query
- * @param $value
- */
- public function searchOrderIdRealNameAttr($query, $value)
- {
- $query->where('order_id|real_name', $value);
- }
- /**
- * 用户ID搜索器
- * @param Model $query
- * @param $value
- */
- public function searchUidAttr($query, $value)
- {
- if (is_array($value))
- $query->whereIn('uid', $value);
- else
- $query->where('uid', $value);
- }
- /**
- * 支付状态搜索器
- * @param Model $query
- * @param $value
- */
- public function searchPaidAttr($query, $value)
- {
- $query->where('paid', $value);
- }
- /**
- * 退款状态搜索器
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchRefundStatusAttr($query, $value, $data)
- {
- if ($value !== '') {
- if (is_array($value)) {
- $query->whereIn('refund_status', $value);
- } else {
- $query->where('refund_status', $value);
- }
- }
- }
- /**
- * 退款状态搜索器
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchRefundStatusInAttr($query, $value)
- {
- $query->whereIn('refund_status', $value);
- }
- /**
- * 是否是拼团订单
- * @param Model $query
- * @param $value
- */
- public function searchPinkIdAttr($query, $value)
- {
- $query->where('pink_id', $value);
- }
- /**
- * 核销码搜索器
- * @param Model $query
- * @param $value
- */
- public function searchVerifyCodeAttr($query, $value)
- {
- $query->where('verify_code', $value);
- }
- /**
- * 支付状态搜索器
- * @param Model $query
- * @param $value
- */
- public function searchIsDelAttr($query, $value)
- {
- if ($value != '') $query->where('is_del', $value);
- }
- /**
- * 是否删除搜索器
- * @param Model $query
- * @param $value
- */
- public function searchIsSystemDelAttr($query, $value)
- {
- if ($value != '') $query->where('is_system_del', $value);
- }
- /**
- * 退款状态搜索器
- * @param $query
- * @param $value
- */
- public function searchRefundTypeAttr($query, $value)
- {
- if (is_array($value)) {
- $query->whereIn('refund_type', $value);
- } else {
- if ($value == -1) {
- $query->where('refund_type', 'in', '0,3');
- } else {
- if ($value == 0 || $value == '') {
- $query->where('refund_type', '<>', 0);
- } else {
- $query->where('refund_type', $value);
- }
- }
- }
- }
- /**
- * 用户来源
- * @param Model $query
- * @param $value
- */
- public function searchChannelTypeAttr($query, $value)
- {
- if ($value != '') $query->where('channel_type', $value);
- }
- /**
- * 退款id搜索器
- * @param Model $query
- * @param $value
- */
- public function searchRefundIdAttr($query, $value)
- {
- if ($value) {
- $query->where('id', 'in', $value);
- }
- }
- /**
- * 上级|上上级推广人
- * @param $query
- * @param $value
- */
- public function searchSpreadOrUidAttr($query, $value)
- {
- if ($value) $query->where('spread_uid|spread_two_uid', $value);
- }
- /**
- * 上级推广人
- * @param $query
- * @param $value
- */
- public function searchSpreadUidAttr($query, $value)
- {
- if ($value) $query->where('spread_uid', $value);
- }
- /**
- * 上上级推广人
- * @param $query
- * @param $value
- */
- public function searchSpreadTwoUidAttr($query, $value)
- {
- if ($value) $query->where('spread_two_uid', $value);
- }
- /**
- * 门店ID
- * @param $query
- * @param $value
- */
- public function searchStoreIdAttr($query, $value)
- {
- if ($value !== '') {
- if ($value == -1) {//所有门店
- $query->where('store_id', '>', 0);
- } else {
- $query->where('store_id', $value);
- }
- }
- }
- /**
- * 门店店员ID
- * @param $query
- * @param $value
- */
- public function searchStaffIdAttr($query, $value)
- {
- if ($value) $query->where('staff_id', $value);
- }
- /**
- * 配送方式
- * @param $query
- * @param $value
- */
- public function searchShippingTypeAttr($query, $value)
- {
- if ($value) {
- if (is_array($value)) {
- $query->where('shipping_type', $value);
- } else {
- $query->where('shipping_type', $value);
- }
- }
- }
- /**
- * 配送员UID
- * @param $query
- * @param $value
- */
- public function searchDeliveryUidAttr($query, $value)
- {
- if ($value) $query->where('delivery_uid', $value);
- }
- /**
- * 配送类型
- * @param $query
- * @param $value
- */
- public function searchDeliveryTypeAttr($query, $value)
- {
- if ($value) $query->where('delivery_type', $value);
- }
- /**
- * 供应商ID
- * @param $query
- * @param $value
- */
- public function searchSupplierIdAttr($query, $value)
- {
- if ($value !== '') {
- if ($value == -1) {
- $query->where('supplier_id', '>', 0);
- } else {
- $query->where('supplier_id', $value);
- }
- }
- }
- /**
- * 支付渠道
- * @param $query
- * @param $value
- */
- public function searchIsChannelAttr($query, $value)
- {
- if ($value !== '') $query->where('is_channel', $value);
- }
- /**
- * 一对一关联供应商
- * @return \think\model\relation\HasOne
- */
- public function supplier()
- {
- return $this->hasOne(SystemSupplier::class, 'id', 'supplier_id')->field(['id', 'supplier_name'])->bind([
- 'supplier_name'
- ]);
- }
- /**
- * 一对一关联供应商
- * @return \think\model\relation\HasOne
- */
- public function supplierInfo()
- {
- return $this->hasOne(SystemSupplier::class, 'id', 'supplier_id')->field(['id', 'supplier_name', 'name', 'phone', 'email']);
- }
- /**
- * 供应商统计
- * @param $query
- * @param $value
- */
- public function searchSupplierAttr($query, $value)
- {
- if ($value !== '') $query->where('supplier_id', '>', 0);
- }
- }
|