| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace addons\WechatVideoShop\common\service;
- use addons\WechatVideoShop\common\models\WechatVideoShopCommission;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use common\models\order\Order;
- class CommissionService
- {
- /**
- * 分页
- * @param int $mall_id
- * @param array $params
- * @return array|false|mixed|string|null
- */
- public function page(int $mall_id, array $params)
- {
- $where = [
- ['mall_id' => $mall_id],
- ['status' => StatusEnum::ENABLED],
- ];
- if (!empty($params['user_id'])) {
- $where[] = ['user_id' => $params['user_id']];
- }
- if (!empty($params['mobile'])) {
- $uids = User::find()
- ->where(['mall_id' => $mall_id])
- ->andWhere(['or', ['like', 'username', $params['mobile']], ['like', 'mobile', $params['mobile']], ['like', 'nickname', $params['mobile']]])
- ->select('id')
- ->column();
- if (empty($uids)) return [];
- $where[] = ['user_id' => $uids];
- }
- if (!empty($params['settle_status'])) {
- $where[] = ['settle_status' => $params['settle_status']];
- }
- if (!empty($params['date_start'])) $where[] = ['>=', 'created_at', strtotime($params['date_start'])];
- if (!empty($params['date_end'])) $where[] = ['<=', 'created_at', strtotime($params['date_end'])];
- $ret = WechatVideoShopCommission::listPage([
- 'where' => $where,
- 'order' => 'id desc',
- 'limit' => $params['limit'] ?? 10,
- 'with' => ['user', 'buyUser']
- ]);
- if (!empty(WechatVideoShopCommission::getStaticError())) return WechatVideoShopCommission::getStaticError();
- return $ret;
- }
- /**
- * @param Order $order
- * @return bool
- * @throws \Exception
- */
- public function create(Order $order)
- {
- // 这里是创建分佣
- $model = new WechatVideoShopCommission();
- $model->mall_id = $order->mall_id;
- $model->user_id = $order->mall_id;
- $model->buy_user_id = $order->mall_id;
- $model->order_no = $order->mall_id;
- $model->order_id = $order->mall_id;
- $model->order_amount = $order->mall_id;
- $model->remark = $order->mall_id;
- $model->settle_status = $order->mall_id;
- $model->commission = $order->mall_id;
- $model->commission_type = $order->mall_id;
- $model->shop_id = 0;
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return true;
- }
- }
|