get_user_id(), 'store_id' => get_store_id(), 'is_delete' => 0]); if (!$share) { $share = new Share(); } $setting = Option::get('share_basic_setting', $this->store_id); $share_setting = $setting ? Json::decode($setting['value']) : []; $form = new ShareForm(); $form->share = $share; $form->store_id = get_store_id(); $form->attributes = post_params(); if ($share_setting['share_condition']['value'] == 1) { $form->scenario = "APPLY"; } elseif ($share_setting['share_condition']['value'] == 0 || $share_setting['share_condition']['value'] == 2) { $form->agree = 1; } return $this->asJson($form->save()); } /** * @return mixed|string * 获取用户的审核状态 */ public function actionCheck() { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => get_user()->is_distributor, 'level' => get_user()->level, 'template_id' => NoticeAction::getSendTamplateId(['share_examine']) ]); } /** * 获取分销中心数据 * @return \yii\web\Response * @throws \yii\db\Exception */ public function actionGetInfo() { if (get_user()->is_distributor != 1) { $data = [ 'is_distributor' => get_user()->is_distributor ]; $not_is_distributor = 0; $setting = Option::get('share_basic_setting', $this->store_id); $share_basic_setting = $setting ? Json::decode($setting['value']) : []; if (in_array((int)$share_basic_setting['share_condition']['value'], [0, 1])) { $not_is_distributor = 1; return $this->asJson([ 'code' => 0, 'msg' => '您还不是分销商', 'not_is_distributor' => $not_is_distributor ]); } } $res = [ 'code' => 0, 'msg' => 'success', ]; $store_id = get_store_id(); //获取分销佣金及提现 $form = new ShareForm(); $form->store_id = $store_id; $form->user_id = get_user()->id; $res['data']['price'] = $form->getPrice(0); //获取我的团队 $team = new TeamForm(); $team->user_id = get_user_id(); $team->store_id = $store_id; $arr = $team->getOrderCount(); $res['data']['team_count'] = get_user_id() ? $arr['team_count'] : 0; $res['data']['order_money'] = get_user_id() ? $arr['order_money'] : 0; $res['data']['order_money_un'] = get_user_id() ? $arr['order_money_un'] : 0; $res['data']['order_count'] = get_user_id() ? intval($arr['order_count']): 0; $res['data']['share_order_count'] = get_user_id() ? intval($arr['share_order_count']) : 0; $team->yinbao = 1; $arr = $team->getOrderCount(); $res['data']['order_count_yinbao'] = get_user_id() ? intval($arr['order_count']) : 0; //获取分销商等级 $share = Share::findOne(['store_id' => $store_id, 'user_id' => get_user_id(), 'is_delete' => 0]); $res['data']['level_name'] = '-'; if ($share) { $share_level = ShareLevel::findOne(['level' => $share->level, 'store_id' => $store_id, 'is_delete' => 0]); if ($share_level) { $res['data']['level_name'] = $share_level->name; } } $shareOption = Option::findOne([ 'store_id' => $store_id, 'group' => OptionSetting::SHARE_GROUP_NAME, 'name' => OptionSetting::SHARE_BASIC_SETTING ]); $shareOption = Json::decode($shareOption['value']); $res['data']['video_share_order_count'] = VideoGoodsShare::find()->where(['author_user_id' => get_user_id()])->groupBy('order_id')->count(); $res['data']['wx_title'] = $shareOption['wx_title']['value'] ?: '分销中心'; //获取分销自定义数据 // $custom_form = new ShareCustomForm(); // $custom_form->store_id = $store_id; // $custom = $custom_form->getData(); // $res['data']['custom'] = $custom['data']; return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res['data']]); } /** * @return mixed|string * 获取佣金相关 */ public function actionGetPrice() { $form = new ShareForm(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $is_team_grades = intval(get_params('is_team_grades')); $is_share_group_purchase = intval(get_params('is_share_group_purchase')); $is_super_sales = intval(get_params('is_super_sales')); $is_integral_appreciation = intval(get_params('is_integral_appreciation')); $res['data']['price'] = $form->getPrice(); if ($is_team_grades) { $userTeamGrades = TeamGrades::getUserTeamGrades(get_user_id()); if ($res['data']['price']['price'] > $userTeamGrades['price']) { $res['data']['price']['price'] = $userTeamGrades['price']; } $setting = Option::get('share_basic_setting', get_store_id()); $setting = $setting ? Json::decode($setting['value']) : []; $res['data']['pay_type'] = 2; $res['data']['bank'] = 1; $res['data']['remaining_sum'] = 0; } elseif ($is_share_group_purchase) { $shareGroupPurchaseUser = ShareGroupPurchaseUser::findOne(['user_id' => get_user_id()]); if ($res['data']['price']['price'] > $shareGroupPurchaseUser->price) { $res['data']['price']['price'] = $shareGroupPurchaseUser->price; } $setting = Option::get('share_group_setting', get_store_id()); $setting = $setting ? Json::decode($setting['value']) : []; $res['data']['pay_type'] = $setting['pay_type'] ?: 0; $res['data']['bank'] = $setting['bank'] ?: 0; $res['data']['lg'] = $setting['lg'] ?: 0; $res['data']['remaining_sum'] = $setting['remaining_sum'] ?: 0; } elseif ($is_super_sales) { $superSalesUser = SuperSalesUser::findOne(['user_id' => get_user_id()]); if ($res['data']['price']['price'] > $superSalesUser->price) { $res['data']['price']['price'] = $superSalesUser->price; } $setting = Option::get('super_sales_setting', get_store_id()); $setting = $setting ? Json::decode($setting['value']) : []; $res['data']['pay_type'] = $setting['pay_type'] ?: 0; $res['data']['bank'] = $setting['bank'] ?: 0; $res['data']['lg'] = $setting['lg'] ?: 0; $res['data']['remaining_sum'] = $setting['remaining_sum'] ?: 0; } elseif ($is_integral_appreciation) { $integralAppreciationUser = IntegralAppreciationUser::findOne(['user_id' => get_user_id()]); //与其他不一样 增值积分需要先根据提现金额 计算一下实际的提现金额 $res['data']['price']['price'] = $integralAppreciationUser->integral ?: '0.00'; $setting = Option::get('integral_appreciation_setting', get_store_id()); $setting = $setting ? Json::decode($setting['value']) : []; // $integralAppreciationPool = IntegralAppreciationPool::findOne(['store_id' => get_store_id()]); // $integral_price = $integralAppreciationPool->integral_price ?: ($setting['integral_init_price'] ?: 0); $res['data']['integral_custom_name'] = $setting['integral_custom_name'] ?: '增值积分'; $res['data']['pay_type'] = $setting['pay_type'] ?: 0; $res['data']['bank'] = $setting['bank'] ?: 0; $res['data']['lg'] = $setting['lg'] ?: 0; $res['data']['remaining_sum'] = $setting['remaining_sum'] ?: 0; } else { $setting = Option::get('share_basic_setting', get_store_id()); $setting = $setting ? Json::decode($setting['value']) : []; $res['data']['pay_type'] = $setting['pay_type']['value']; $res['data']['bank'] = $setting['bank']['value']; $res['data']['lg'] = $setting['lg']['value']; $res['data']['remaining_sum'] = $setting['remaining_sum']['value']; } $cash_last = Cash::find()->where(['store_id' => get_store_id(), 'user_id' => get_user_id(), 'is_delete' => 0]) ->orderBy(['id' => SORT_DESC])->select(['name', 'mobile', 'type', 'bank_name'])->asArray()->one(); $res['data']['cash_last'] = $cash_last; $cash_max_day = floatval($setting['cash_max_day']['value']); if ($is_share_group_purchase || $is_super_sales) { $cash_max_day = floatval($setting['cash_max_day']); } if ($cash_max_day && !$is_team_grades) { $query = Cash::find()->where([ 'store_id' => get_store_id(), 'is_delete' => 0, 'status' => [0, 1, 2, 5], ]); if ($is_share_group_purchase) { $query->andWhere(['cash_type' => Cash::IS_CASH_TYPE_SHARE_GROUP_PURCHASE]); } elseif ($is_super_sales) { $query->andWhere(['cash_type' => Cash::IS_CASH_TYPE_SUPER_SALES]); } else { $query->andWhere(['cash_type' => Cash::IS_CASH_TYPE_SHARE]); } $cash_sum = $query->andWhere([ 'AND', ['>=', 'created_at', strtotime(date('Y-m-d 00:00:00'))], ['<=', 'created_at', strtotime(date('Y-m-d 23:59:59'))], ])->sum('price'); $cash_max_day = $cash_max_day - ($cash_sum ? $cash_sum : 0); $res['data']['cash_max_day'] = max(0, floatval(sprintf('%.2f', $cash_max_day))); } else { $res['data']['cash_max_day'] = -1; } if ($res['data']['cash_max_day'] !== 0) { $cash_max_single_day = $setting['cash_max_single_day']['value']; if ($is_share_group_purchase) { $cash_max_single_day = $setting['cash_max_single_day']; } if ($cash_max_single_day) { //cash_max_day = 2 cash_max_single_day = 3 2 // 3 2 if ($res['data']['cash_max_day'] > $cash_max_single_day) { $res['data']['cash_max_day'] = $cash_max_single_day; } } else { $res['data']['cash_max_day'] = -1; } } $cashServiceCharge = floatval($setting['cash_service_charge']['value']); $res['data']['cash_service_charge'] = $cashServiceCharge; if ($is_share_group_purchase) { $cashServiceCharge = floatval($setting['cash_service_charge']); $res['data']['cash_service_charge'] = $cashServiceCharge; } if($cashServiceCharge == 0 || $is_team_grades){ $res['data']['service_content'] = ""; }else{ $res['data']['service_content'] = "提现需要加收{$cashServiceCharge}%手续费"; } $wxappUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/wxapp/images'; $payTypeList = [ [ 'icon' => $wxappUrl . '/icon-share-wechat.png', 'name' => '微信', 'is_show' => false ], [ 'icon' => $wxappUrl . '/icon-share-ant.png', 'name' => '支付宝', 'is_show' => false ], [ 'icon' => $wxappUrl . '/icon-share-bank.png', 'name' => '银行卡', 'is_show' => false ], [ 'icon' => $wxappUrl . '/gold.png', 'name' => '余额', 'is_show' => false ], [ 'icon' => $wxappUrl . '/icon-share-bank.png', 'name' => '灵工提现', 'is_show' => false ], ]; switch($res['data']['pay_type']){ case 0: $payTypeList[0]['is_show'] = true; break; case 1: $payTypeList[1]['is_show'] = true; break; case 2: $payTypeList[0]['is_show'] = true; $payTypeList[1]['is_show'] = true; break; default: break; } if($res['data']['bank'] && $res['data']['bank'] == 1){ $payTypeList[2]['is_show'] = true; } //灵工提现 if($res['data']['lg'] && $res['data']['lg'] == 1){ $payTypeList[4]['is_show'] = true; } if($res['data']['remaining_sum'] && $res['data']['remaining_sum'] == 1){ $payTypeList[3]['is_show'] = true; } $res['data']['pay_type_list'] = $payTypeList; $res['data']["cash_success_tpl"] = ''; $res['data']["cash_fail_tpl"]= ''; //获取分销订单 $res['data']['fx_list'] = Cash::find()->Where(['user_id' => get_user_id(), 'store_id' => get_store_id()]) ->orderBy('id desc')->asArray()->one(); // 新提现方式 $res['data']['cash_method_list'] = []; $saas_user = get_saas_user(); $cash_method = []; if (!empty($saas_user->withdraw_method)) { $cash_method = json_decode($saas_user->withdraw_method, true); } $money = [ [ 'type' => 'money' ] ]; $cash_method = array_merge($cash_method, $money); //判断是否灵工进件 $lg_info = Lg::find()->where(['user_id' => $saas_user->id, 'store_id' => get_store_id(),'status'=>1,'is_delete'=>0])->one(); if ($lg_info){ $lg = [ [ 'type' => 'lg' ] ]; $cash_method = array_merge($cash_method, $lg); } if (is_array($cash_method)) { foreach ($cash_method as $index => &$item) { if ($item['type'] === 'wechat' && $payTypeList[0]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'alipay' && $payTypeList[1]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'bank_card' && $payTypeList[2]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'money' && $payTypeList[3]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'lg' && $payTypeList[4]['is_show'] === false) { unset($cash_method[$index]); } } $res['data']['cash_method_list'] = array_values($cash_method);; } return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res['data']]); } /** * 获取提现方式 */ public function actionGetCashMethod() { $saas_user = get_saas_user(); $cash_method = []; $payTypeList = [ [ 'name' => '微信', 'is_show' => false, 'type' => 'wechat', 'is_bind' => false ], [ 'name' => '支付宝', 'is_show' => false, 'type' => 'alipay', 'is_bind' => false ], [ 'name' => '银行卡', 'is_show' => false, 'type' => 'bank_card', 'is_bind' => false ], [ 'name' => '灵工提现', 'is_show' => false, 'type' => 'lg', 'is_bind' => false ], ]; if (get_params('is_share_recharge') || get_params('is_share_group_purchase') || get_params('is_super_sales') || get_params('is_integral_appreciation')) { $setting = Option::get('share_basic_setting', get_store_id()); $setting = $setting ? Json::decode($setting['value']) : []; $res['data']['pay_type'] = $setting['pay_type']['value']; $res['data']['bank'] = $setting['bank']['value']; $res['data']['remaining_sum'] = $setting['remaining_sum']['value']; $res['data']['lg'] = $setting['lg']['value']; if (intval(get_params('is_share_group_purchase')) || intval(get_params('is_super_sales')) || intval(get_params('is_integral_appreciation'))) { if (intval(get_params('is_share_group_purchase'))) { $setting = Option::get('share_group_setting', get_store_id()); } elseif (intval(get_params('is_integral_appreciation'))) { $setting = Option::get('integral_appreciation_setting', get_store_id()); } else { $setting = Option::get('super_sales_setting', get_store_id()); } $setting = $setting ? Json::decode($setting['value']) : []; $res['data']['pay_type'] = $setting['pay_type']; $res['data']['bank'] = $setting['bank']; $res['data']['remaining_sum'] = $setting['remaining_sum']; $res['data']['lg'] = $setting['lg']; } switch($res['data']['pay_type']){ case 0: $payTypeList[0]['is_show'] = true; break; case 1: $payTypeList[1]['is_show'] = true; break; case 2: $payTypeList[0]['is_show'] = true; $payTypeList[1]['is_show'] = true; break; default: break; } if($res['data']['bank'] && $res['data']['bank'] == 1){ $payTypeList[2]['is_show'] = true; } if($res['data']['lg'] && $res['data']['lg'] == 1){ $payTypeList[3]['is_show'] = true; } } elseif (intval(get_params('is_rider'))) {//骑手配置 $local_type = Option::get(OptionSetting::STORE_LOCAL_TYPE, get_store_id(), 'store')['value']; $local_type = Option::get(OptionSetting::STORE_LOCAL_TYPE, get_store_id(), 'pay', $local_type); $store_id = $local_type['value'] === 'self_store' ? get_store_id() : 0; $setting = Option::get(OptionSetting::LOCAL_DELIVERY_SETTING, $store_id, OptionSetting::LOCAL_DELIVERY_GROUP_NAME, '')['value']; $setting = $setting ? Json::decode($setting) : []; if (!empty($setting['pay_type']['value'])) { foreach ($payTypeList as &$item) { if ($item['type'] === 'bank_card') { $type = "bank"; } else { $type = $item['type']; } if (in_array($type, $setting['pay_type']['value'])) { $item['is_show'] = 1; } } } unset($item); } elseif (intval(get_params('is_team_grades'))) {//团队业绩分红 foreach ($payTypeList as &$item) { $item['is_show'] = true; } unset($item); } else { $balanceToCashSet = json_decode(Option::get(OptionSetting::BALANCE_TO_CASH_SETTING, $this->store_id, 'recharge', '')['value'], true); if (!empty($balanceToCashSet)) { $balance_to_cash_pay_type = $balanceToCashSet['balance_to_cash_pay_type']; $store = Store::findOne($this->store_id); foreach ($payTypeList as &$item) { foreach ($balance_to_cash_pay_type as $type_index => $type_item) { if ($type_index === $item['type']) { if (intval($type_item) === 1) { $item['is_show'] = true; } } } if ('lg' === $item['type'] && $store->lg_cash) { $item['is_show'] = true; } } } unset($item); } if (!empty($saas_user->withdraw_method)) { $decode = json_decode($saas_user->withdraw_method, true); if (is_array($decode)) { $cash_method = $decode; foreach ($payTypeList as &$pay_item) { foreach ($cash_method as $item) { if ($item['type'] === $pay_item['type']) { $pay_item['is_bind'] = true; $pay_item = array_merge($pay_item, $item); } } } } } //判断灵工是否绑定 foreach ($payTypeList as &$item){ $lg = Lg::find()->where(['user_id' => $saas_user->id,'is_delete'=>0,'status'=>1])->one(); if ($lg){ if ('lg' === $item['type']) { $item['is_bind'] = true; $item = array_merge($item, $item); } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $payTypeList, ], ]); } /** * 获取提现方式 */ public function actionDelCashMethod() { $saas_user = get_saas_user(); $type = post_params('type'); if (empty($type)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } if ($type == 'lg'){ $lg = Lg::find()->where(['user_id'=>$saas_user->id,'is_delete'=>0])->one(); if ($lg){ $lg->is_delete = 1; $lg->save(); return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } } if (empty($saas_user->withdraw_method)) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } $cash_method = json_decode($saas_user->withdraw_method, true); if (is_array($cash_method)) { foreach ($cash_method as $key => $value) { if ($value['type'] == $type) { unset($cash_method[$key]); } } $saas_user->withdraw_method = json_encode(array_values($cash_method)); } else { $saas_user->withdraw_method = ''; } if ($saas_user->save()) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } return $this->asJson([ 'code' => 0, 'msg' => '操作失败', ]); } /** * 添加提现方式 */ public function actionAddCashMethod() { $type = post_params('type'); if (empty($type)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $name = post_params('name'); $account = post_params('account'); $bank = post_params('bank'); $branch = post_params('branch'); $card_no = post_params('card_no'); $cash_img = post_params('cash_img'); if (empty($name) || empty($account)) { return $this->asJson([ 'code' => 1, 'msg' => '账号和姓名不能为空', ]); } if ($type == 'bank_card' && (empty($bank) || empty($card_no))) { return $this->asJson([ 'code' => 1, 'msg' => '银行或支行不能为空', ]); } $data = [ 'type' => $type, 'name' => $name, 'account' => $account, 'cash_img' => $cash_img, ]; if ($type == 'bank_card') { $data['bank'] = $bank; $data['branch'] = $branch; $data['card_no'] = $card_no; } $saas_user = get_saas_user(); if (empty($saas_user->withdraw_method)) { $saas_user->withdraw_method = json_encode(array_values([$data])); } else { $decode = json_decode($saas_user->withdraw_method, true); if (!$decode) { $saas_user->withdraw_method = json_encode(array_values([$data])); } else { foreach ($decode as $key => $value) { if ($value['type'] == $type) { unset($decode[$key]); break; } } $decode[] = $data; $saas_user->withdraw_method = json_encode(array_values($decode)); } } if ($saas_user->save()) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } return $this->asJson([ 'code' => 1, 'msg' => '操作失败', ]); } //提现前置计算 public function actionGetCashFront() { $post = post_params(); $price = $post['price']; $cash_type = $post['cash_type']; $type = $post['type']; if (!in_array($cash_type, CashExt::CASH_TYPE_ARR)) { return $this->asJson([ 'code' => 1, 'msg' => '提现类型错误', ]); } $store_id = get_store_id(); if ($cash_type == CashExt::CASH_TYPE_INTEGRAL_APPRECIATION) { $price = CashExt::integral_appreciation_cash($price, $store_id)['cash_price']; } // 分销提现 股东提现 到余额的不扣除手续费 return $this->asJson(CashExt::cashFront($cash_type, $store_id, $price, $type == 'money' ? 3 : 0)); } /** * @return mixed|string * 申请提现 */ public function actionApply() { $form = new CashForm(); $form->user_id = get_user_id(); $form->store_id = get_store_id(); $form->attributes = post_params(); return $this->asJson($form->save()); } /** * 提现明细列表 */ public function actionCashDetail() { $form = new CashListForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->getList()); } /** * @return mixed|string * 获取推广海报 */ public function actionGetQrcode() { $form = new ShareQrcodeForm(); $form->store_id = get_store_id(); $form->type = 4; $form->user = get_user(); $form->user_id = get_user_id(); //判断是否是分销商 $share = Share::findOne(['user_id' => get_user_id(), 'status' => 1, 'is_delete' => 0]); if (empty($share)) { return $this->asJson([ 'code' => 0, 'data' => '', 'status' => 1, 'msg' => '您还不是分销商' ]); } return $this->asJson($form->search()); } /** * @return mixed|string * 商店分销设置信息 */ // TODO: ??? public function actionShopShare() { // $list = Setting::find()->alias('s') // ->where(['s.store_id' => get_store_id()]) // ->leftJoin('{{%qrcode}} q', 'q.store_id=s.store_id and q.is_delete=0') // ->select(['s.level', 'q.qrcode_bg']) // ->asArray()->one(); // return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $list]); } /** * @return mixed|string * 绑定上下级关系 */ public function actionBindParent() { $form = new BindForm(); $form->user_id = get_user_id(); $form->store_id = get_store_id(); $form->parent_id = get_params('parent_id'); $form->condition = intval(get_params('condition')); $form->page_type = intval(all_params('page_type')); return $this->asJson($form->save()); } /** * @return mixed|string * 获取团队详情 */ public function actionGetTeam() { $form = new TeamForm(); $form->attributes = get_params(); $form->user_id = get_user_id(); $form->store_id = get_store_id(); $form->scenario = "TEAM"; return $this->asJson($form->getTeam()); } /** * 获取分销订单 * @return \yii\web\Response * @throws \yii\db\Exception */ public function actionGetOrder() { $form = new TeamForm(); $form->attributes = get_params(); $form->user_id = get_user_id(); $form->child_user_id = get_params('child_user_id'); $form->store_id = get_store_id(); $form->scenario = "ORDER"; return $this->asJson($form->getOrder()); } /** * @description: 充值订单 * @param {*} $user * @return {*} */ public function actionGetRechargeOrder() { $user = get_user(); $form = new RcCommissionForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->status = get_params('status'); $form->page = get_params('page'); $form->user = $user; $res = $form->search(); return $this->asJson($res); } /** * 获取分销订单 * @return \yii\web\Response * @throws \yii\db\Exception */ public function actionGetOrder2() { $form = new TeamForm(); $form->attributes = get_params(); $form->user_id = get_user_id(); $form->store_id = get_store_id(); $form->scenario = "ORDER"; return $this->asJson($form->getOrder2()); } /** * 修改分销订单门店 */ public function actionSetOrderMdId() { $order_id = get_params('order_id'); $md_id = get_params('md_id'); $order = Order::findOne($order_id); if (!$order) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在' ]); } $md = Md::findOne($md_id); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '门店不存在' ]); } $order->md_id = $md_id; $order->save(); return $this->asJson([ 'code' => 0, 'msg' => '修改成功' ]); } public function actionGetShareOrder() { $store_id = get_store_id(); $user_id = get_user_id(); $page = get_params('page', 1); $limit = get_params('limit', 20); $query = UserShareMoney::find()->alias('usm')->where(['usm.store_id' => $store_id, 'usm.user_id' => $user_id, 'usm.type' => 0, 'usm.source' => 5])->leftJoin(['o' => Order::tableName()], 'o.id = usm.order_id') ->leftJoin(['u' => User::tableName()], 'u.id=usm.user_id') ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding'); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('o.*, su.avatar as avatar_url, su.name as nickname')->orderBy('usm.created_at desc') ->limit($pagination->limit) ->offset($pagination->offset)->asArray()->all(); $new_list = []; foreach ($list as $index => $value) { $new_list[$index]['share_send_type'] = $value['share_send_type']; $new_list[$index]['order_type'] = $value['order_type']; $new_list[$index]['order_no'] = $value['order_no']; $new_list[$index]['nickname'] = $value['nickname']; $new_list[$index]['avatar_url'] = $value['avatar_url']; $new_list[$index]['is_price'] = $value['is_price']; $new_list[$index]['status'] = "待付款"; if ($value['is_pay'] == 0) { $new_list[$index]['status'] = "待付款"; } elseif ($value['is_pay'] == 1 && $value['is_price'] == 0) { $new_list[$index]['status'] = "已付款"; } elseif ($value['is_price'] == 1) { $new_list[$index]['status'] = "已完成"; } $new_list[$index]['share_status'] = '分享返现'; $new_list[$index]['share_money'] = $value['share_order_profit']; // 订单商品详情 $form = new TeamForm(); $new_list[$index]['orderDetail'] = $form->getOrderDetail($value['id']); $refund = OrderRefund::findOne(['order_id' => $value['id'], 'is_delete' => 0, 'store_id' => $this->store_id, 'type' => 1]); if ($refund) { if ($refund['status'] == 1) { $new_list[$index]['status'] = "已退款"; } elseif ($refund['status'] == 0) { $new_list[$index]['status'] = '售后申请中'; } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $new_list, ] ]); } /** * 获取分销配置 * @return \yii\web\Response */ public function actionIndex() { $form = new ShareForm(); $form->store_id = get_store_id(); return $this->asJson($form->getShareSetting()); } //佣金明细 public function actionGetUserShareMoney() { $store_id = get_store_id(); $user_id = get_user_id(); $query = UserShareMoney::find() ->where(['store_id' => $store_id, 'user_id' => $user_id]) // 如果记录money为0,不显示 ->andWhere(['>', 'money', 0]) // ->alias('usm') // ->where(['usm.store_id' => $store_id, 'usm.user_id' => $user_id, 'usm.type' => 0]) // ->leftJoin(['o' => Order::tableName()], 'o.id = usm.order_id and usm.order_type in (0, 1, 2, 3)') // ->leftJoin(['lo' => LevelOrder::tableName()], 'lo.id = usm.order_id and usm.order_type = 4') // ->leftJoin(['ro' => ReOrder::tableName()], 'ro.id = usm.order_id and usm.order_type = 5') // ->select('usm.*, o.order_no, lo.order_no l_order_no, ro.order_no r_order_no') ->orderBy('id DESC'); $list = pagination_make($query); foreach ($list['list'] as &$item) { //提需求说是要显示佣金来源的详细信息 $desc = ""; if (in_array($item['order_type'], [0, 1, 2, 3])) { $order = Order::findOne($item['order_id']); //提需求说是要显示xx用户购买了xx等多件商品 产生的以及/二级佣金 $orderDetail = OrderDetail::find()->where(['order_id' => $item['order_id'], 'is_delete' => 0]) ->select('goods_name, num')->asArray()->all(); $desc .= "购买"; $goods_str = ''; foreach ($orderDetail as $order_goods_item) { $goods_str .= $order_goods_item['goods_name']; } $goods_str = mb_substr($goods_str, 0, 15, 'utf-8'); // 去除非utf8字符 if (function_exists('iconv')) { // 使用iconv函数去除非UTF-8字符 $goods_str = iconv('UTF-8', 'UTF-8//IGNORE', $goods_str); } else { // 如果iconv不可用,则使用正则表达式尝试去除非UTF-8字符 $goods_str = preg_replace('/[^\x{0000}-\x{FFFF}]/u', '', $goods_str); } $desc .= $goods_str . "……等商品产生的" . UserShareMoney::getSourceName($item['source'], $store_id) . "佣金"; } elseif (intval($item['order_type']) === 4) { $order = LevelOrder::findOne($item['order_id']); $level_name = ""; if ($order) { $level = Level::findOne(['store_id' => $store_id, 'level' => $order->after_level, 'is_delete' => 0]); $level_name = $level->name ?? ''; } $desc .= "购买{$level_name}等级"; } elseif (intval($item['order_type']) === 5) { $order = ReOrder::findOne($item['order_id']); } $user = [ 'name' => '' ]; if (!empty($order)) { $user = User::find()->alias('u')->where(['u.id' => $order->user_id]) ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')->select('su.name') ->asArray()->one(); } $desc = '商城会员: ' . $user['name'] . $desc; $item['order_no'] = $order->order_no ?? ''; $item['l_order_no'] = $order->order_no ?? ''; $item['r_order_no'] = $order->order_no ?? ''; $item['source_name'] = UserShareMoney::getSourceName($item['source'], $store_id); $item['source_desc'] = ""; // if (intval($item['order_type']) === 4 && !empty($order)) { // // } $item['source_desc'] = $desc; if (!$item['order_no']) { $item['order_no'] = $item['l_order_no']; } if(!$item['l_order_no'] && !$item['order_no']){ $item['order_no'] = $item['r_order_no']; } $item['type'] = intval($item['type']); } $list['data'] = $list['list']; unset($list['list']); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $list, ]); } }