| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <?php
- namespace app\modules\client\models\v1\super_sales;
- use app\models\Cash;
- use app\models\Goods;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\Qrcode;
- use app\models\SaasUser;
- use app\models\Store;
- use app\models\SuperSales;
- use app\models\SuperSalesMoney;
- use app\models\SuperSalesSub;
- use app\models\SuperSalesUser;
- use app\models\User;
- use app\modules\client\models\v1\ShareQrcodeForm;
- use app\utils\ShareQrcode;
- class SuperSalesForm extends \yii\base\Model
- {
- public $user;
- public $saas_user;
- public $store_id;
- public $status;
- public $name;
- public $type;
- public $id;
- public function rules()
- {
- return [
- [['store_id', 'status', 'type', 'id'], 'integer'],
- [['name'], 'string']
- ];
- }
- //超级卖货中心
- public function index() {
- $store_id = $this->store_id;
- $user = $this->user;
- $saasUser = $this->saas_user;
- $superSalesUser = SuperSalesUser::findOne(['user_id' => $user->id]);
- $parent_user_info = User::findOne($superSalesUser->parent_user_id ?? $user->old_parent_id);
- $user_info = [
- 'name' => $user->nickname,
- 'avatar' => $user->avatar_url,
- 'parent_name' => $parent_user_info->nickname ?? '总店',
- ];
- //用户佣金 可提现佣金
- $wait_cash_amount = $user->price >= $superSalesUser->price ? $superSalesUser->price : $user->price;
- //用户佣金 未到账佣金
- $no_send_amount = SuperSalesMoney::find()->where(['user_id' => $user->id, 'status' => SuperSalesMoney::STATUS_NOT_SEND])
- ->select('money')->sum('money') ?: '0.00';
- //用户佣金 已提现佣金
- $cash_amount = Cash::find()->where(['user_id' => $user->id, 'cash_type' => Cash::IS_CASH_TYPE_SUPER_SALES, 'status' => [
- Cash::STATUS_GIVEN,
- Cash::STATUS_HAND,
- Cash::STATUS_RECHARGE
- ]])
- ->select('price')->sum('price') ?: '0.00';
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- 'user_info' => $user_info,
- 'wait_cash_amount' => $wait_cash_amount,//可提现佣金
- 'no_send_amount' => $no_send_amount,//未到账佣金
- 'cash_amount' => $cash_amount,//已提现佣金
- 'total_amount' => bcadd($superSalesUser->group_award, $superSalesUser->direct_award, 2)//累计佣金
- ]
- ];
- }
- //分红奖
- public function dividendAwardList() {
- $status = $this->status;
- $user = $this->user;
- $query = SuperSalesMoney::find()->alias('sm')
- ->leftJoin(['ss' => SuperSales::tableName()], 'sm.sales_id = ss.id')
- ->where(['sm.user_id' => $user->id, 'sm.type' => SuperSalesMoney::TYPE_GROUP_AWARD]);
- if (isset($status) && in_array($status, [SuperSalesMoney::STATUS_NOT_SEND, SuperSalesMoney::STATUS_SEND])) {
- $query->andWhere(['sm.status' => $status]);
- }
- $query->select('sm.id, sm.money, sm.status, sm.send_time, ss.created_at, ss.finish_time, sm.sales_id')
- ->orderBy('sm.id DESC');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['id'] = $item['sales_id'];
- $item['status'] = intval($item['status']);
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['finish_time'] = $item['finish_time'] > 0 ? date('Y-m-d H:i:s', $item['finish_time']) : '';
- $item['send_time'] = $item['status'] ? date('Y-m-d H:i:s', $item['send_time']) : '暂未到账';
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- //直推奖 | 佣金明细(全部佣金)
- public function directAwardList() {
- $status = $this->status;
- $user = $this->user;
- $type = $this->type;
- $query = SuperSalesMoney::find()->alias('sm')
- ->leftJoin(['o' => Order::tableName()], 'sm.order_id = o.id')
- ->where(['sm.user_id' => $user->id]);
- if (!$type) {
- $query->andWhere(['sm.type' => SuperSalesMoney::TYPE_DIRECT_AWARD]);
- }
- if (isset($status) && in_array($status, [SuperSalesMoney::STATUS_NOT_SEND, SuperSalesMoney::STATUS_SEND])) {
- $query->andWhere(['sm.status' => $status]);
- }
- $query->select('sm.id, sm.money, sm.status, sm.send_time, sm.created_at money_created_at, sm.type, o.created_at, o.user_id, o.order_no')
- ->orderBy('sm.id DESC');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['status'] = intval($item['status']);
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['money_created_at'] = date('Y-m-d H:i:s', $item['money_created_at']);
- $item['send_time'] = $item['status'] ? date('Y-m-d H:i:s', $item['send_time']) : '暂未到账';
- $binding = User::findOne(['id' => $item['user_id'], 'is_delete' => 0])->binding;
- $user = SaasUser::find()->where(['mobile' => $binding])
- ->select('name')->asArray()->One();
- $item['order_user_name'] = $user['name'] ?: '';
- $item['award_name'] = SuperSalesMoney::$typeMap[$item['type']];
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- //团列表
- public function superSalesList() {
- $user = $this->user;
- $superSalesArray = SuperSalesSub::find()->where(['user_id' => $user->id])->orderBy('id DESC')
- ->select('sales_id')->column() ?: [];
- $query = SuperSales::find()->alias('ss')
- ->leftJoin(['u' => User::tableName()], 'ss.user_id = u.id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile = u.binding')
- ->where(['ss.id' => $superSalesArray])
- ->select('ss.id, ss.created_at, ss.status, su.name, su.avatar')->orderBy('ss.id DESC');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['num'] = SuperSalesSub::find()->where(['sales_id' => $item['id']])->count();
- $item['status'] = intval($item['status']);
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- //团信息
- public function superSalesInfo() {
- $superSalesId = $this->id;
- $superSalesSub = SuperSalesSub::find()->alias('sss')
- ->leftJoin(['o' => Order::tableName()], 'sss.order_id = o.id')
- ->leftJoin(['u' => User::tableName()], 'o.user_id = u.id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile = u.binding')
- ->where(['sss.sales_id' => $superSalesId])
- ->select('sss.id, sss.points, o.order_no, o.created_at, su.name, su.avatar, sss.order_detail_id')
- ->orderBy('sss.points DESC')
- ->asArray()->all();
- foreach ($superSalesSub as &$subItem) {
- $order_detail_id = explode(',', $subItem['order_detail_id']);
- $subItem['goods_list'] = OrderDetail::find()->where(['id' => $order_detail_id, 'is_delete' => 0])
- ->select('goods_id, total_price, goods_name, num, pic, attr')->asArray()->all();
- foreach ($subItem['goods_list'] as &$goods_item) {
- $goods_item['attr'] = json_decode($goods_item['attr'], true);
- }
- $subItem['created_at'] = date('Y-m-d H:i:s', $subItem['created_at']);
- $is_send = SuperSalesMoney::findOne(['sales_sub_id' => $subItem['id'], 'status' => SuperSalesMoney::STATUS_NOT_SEND]);
- if ($is_send) {
- $subItem['status'] = '待入账';
- $subItem['money'] = SuperSalesMoney::find()->where(['sales_sub_id' => $subItem['id'], 'status' => SuperSalesMoney::STATUS_NOT_SEND])
- ->sum('money') ?: '0.00';
- } else {
- $subItem['status'] = '已入账';
- $subItem['money'] = SuperSalesMoney::find()->where(['sales_sub_id' => $subItem['id']])
- ->sum('money') ?: '0.00';
- }
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- 'list' => $superSalesSub
- ]
- ];
- }
- public function superSalesGoods() {
- $store_id = $this->store_id;
- $super_sales_setting = Option::get('super_sales_setting', $store_id, 'super_sales')['value'];
- $super_sales_setting = json_decode($super_sales_setting ?? '', true);
- $goods_ids = explode(',', $super_sales_setting['goods_ids'] ?? '');
- $query = Goods::find()->where(['id' => $goods_ids, 'is_delete' => 0, 'status' => Goods::STATUS_NORMAL])
- ->select('id, name, price, cover_pic');
- $list = pagination_make($query);
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- //我的推荐
- public function myRecommend() {
- $user = $this->user;
- $name = $this->name;
- $query = SuperSalesUser::find()->alias('ssu')
- ->leftJoin(['u' => User::tableName()], 'ssu.user_id = u.id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile = u.binding')
- ->where(['ssu.parent_user_id' => $user->id]);
- if ($name) {
- $query->andWhere(['like', 'su.name', $name]);
- }
- $query->select('ssu.id, su.name, su.avatar, ssu.created_at, ssu.user_id');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['num'] = SuperSales::find()->where(['user_id' => $item['user_id'], 'status' => SuperSales::STATUS_FINISH])
- ->count();
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- //我的二维码
- public function myQrcode() {
- $user = $this->user;
- $store_id = $this->store_id;
- $store = Store::findOne($store_id);
- $store_info = [
- 'name' => $store->name,
- 'logo' => $store->logo ?: (Option::get('logo', $store_id, 'store')['value'] ?: Option::get('web_log', $store_id, 'web')['value']),
- ];
- $url_path = '';
- try {
- $form = new ShareQrcodeForm();
- $form->store_id = $store_id;
- $form->type = Qrcode::TYPE_SUPER_SALES;
- $form->user_id = $user->id;
- $result = $form->search();
- if ($result['code']) {
- throw new \Exception($result['msg']);
- }
- $url_path = $result['data'];
- } catch (\Exception $e) {
- debug_log([
- 'code' => $e->getCode(),
- 'message' => $e->getMessage(),
- 'file' => $e->getFile(),
- 'line' => $e->getLine(),
- ], 'group_purchase_qrcode.log');
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- // 'store_info' => $store_info,
- 'qrcode_url' => $url_path,
- ]
- ];
- }
- // private function getQrcode($scene, $width = 240, $page = null)
- // {
- //
- // if (is_alipay_platform()) {
- // $res = ShareQrcode::getAlipayQrcode($page ?: 'pages/home/home', $scene);
- // if (empty($res['code']) || $res['code'] != 10000) {
- // return $res;
- // }
- // $res['url_path'] = $res['qr_code_url_circle_blue'];
- // return $res;
- // } else {
- // return ShareQrcode::wxQrcode($page, $scene, $width);
- // }
- //
- // }
- }
|