123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2023 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\system\store\SystemStore;
- use app\model\system\store\SystemStoreStaff;
- use app\model\user\User;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use think\Model;
- /**
- * TODO 订单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
- * @return array|mixed
- */
- public function setCustomFormAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
- /**
- * 自定义表单获取器
- * @param $value
- * @return array|mixed
- */
- public function getCustomFormAttr($value)
- {
- return is_string($value) ? json_decode($value, true) ?? [] : [];
- }
- /**
- * 一对多关联查询子订单
- * @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')->field(['uid', 'nickname', 'phone', 'spread_uid'])->bind([
- 'nickname' => 'nickname',
- 'phone' => 'phone'
- ]);
- }
- public function division()
- {
- return $this->hasOne(User::class, 'uid', 'division_id')->field(['uid', 'nickname'])->bind([
- 'division_name' => 'nickname'
- ]);
- }
- /**
- * 一对一关联上级用户信息
- * @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')->field(['id', 'name'])->bind([
- 'store_name' => '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 invoice()
- {
- return $this->hasOne(StoreOrderInvoice::class, 'order_id', 'id');
- }
- /**
- * 一对多关联退款订单
- * @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);
- }
- /**
- * 购物车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 searchPidAttr($query, $value)
- {
- if ($value === 0) {
- $query->where('pid', '>=', 0);
- } 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)
- {
- if (in_array($value, [0, 1])) {
- $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);
- }
- /**
- * 拼团id搜索器
- * @param Model $query
- * @param $value
- */
- public function searchCombinationIdAttr($query, $value)
- {
- $query->where('combination_id', $value);
- }
- /**
- * 没有拼团订单或拼团商品
- * @param Model $query
- * @param $value
- */
- public function searchCpIdGtAttr($query, $value)
- {
- $query->where('combination_id|pink_id', '>', $value);
- }
- /**
- * 不是秒杀搜索器
- * @param Model $query
- * @param $value
- */
- public function searchSeckillIdGtAttr($query, $value)
- {
- $query->where('seckill_id', '>', $value);
- }
- /**
- * 秒杀id商品搜索器
- * @param Model $query
- * @param $value
- */
- public function searchSeckillIdAttr($query, $value)
- {
- $query->where('seckill_id', $value);
- }
- /**
- * 砍价商品id搜索器
- * @param Model $query
- * @param $value
- */
- public function searchBargainIdAttr($query, $value)
- {
- $query->where('bargain_id', $value);
- }
- /**
- * 属于砍价搜索器
- * @param Model $query
- * @param $value
- * @param $data
- */
- public function searchBargainIdGtAttr($query, $value)
- {
- $query->where('bargain_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);
- }
- /**
- * 支付渠道
- * @param $query
- * @param $value
- */
- public function searchIsChannelAttr($query, $value)
- {
- if ($value !== '') $query->where('is_channel', $value);
- }
- /**
- * 活动查询0普通,1秒杀,2砍价,3拼团,4预售
- * @param $query
- * @param $value
- * @param $data
- */
- public function searchActivityTypeAttr($query, $value, $data)
- {
- if ($value !== '') {
- switch ($value) {
- case 0:
- $query->where('combination_id', 0)->where('seckill_id', 0)->where('bargain_id', 0)->where('advance_id', 0);
- break;
- case 1:
- $query->where('seckill_id', '>', 0);
- break;
- case 2:
- $query->where('bargain_id', '>', 0);
- break;
- case 3:
- $query->where('combination_id', '>', 0);
- break;
- case 4:
- $query->where('advance_id', '>', 0);
- break;
- default:
- break;
- }
- }
- }
- /**
- * 事业部推广订单
- * @param $query
- * @param $value
- */
- public function searchDivisionIdAttr($query, $value)
- {
- if ($value !== '') $query->where('division_id', $value);
- }
- /**
- * 代理商推广订单
- * @param $query
- * @param $value
- */
- public function searchAgentIdAttr($query, $value)
- {
- if ($value !== '') $query->where('agent_id', $value);
- }
- /**
- * @param $query
- * @param $value
- */
- public function searchIdsAttr($query, $value)
- {
- if (is_string($value)) $value = explode(',', $value);
- if (count($value)) $query->whereIn('id', $value);
- }
- }
|