| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\controllers;
- use app\models\BusinessMember;
- use app\models\BusinessMemberOrder;
- use app\models\Cash;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderTransit;
- use app\models\PurchaseOrder;
- use app\models\PurchaseOrderDetail;
- use app\models\SaasSupplierReferral;
- use app\models\ScanCodePayOrder;
- use app\models\OrderDetail;
- use app\models\OrderRefund;
- use app\models\SaasShareMoney;
- use app\models\SaasUser;
- use app\models\Share;
- use app\models\ShareDetail;
- use app\models\StoreShareMoney;
- use app\models\Supplier;
- use app\models\User;
- use app\models\UserShareLog;
- use app\models\UserShareMoney;
- use app\models\SaasStoreReferral;
- use app\models\Store;
- use app\models\SharingReceiver;
- use app\modules\alliance\controllers\BaseController;
- use app\modules\alliance\models\ShareForm;
- use app\modules\alliance\models\CashForm;
- use app\modules\alliance\models\CashListForm;
- use app\modules\alliance\models\TeamForm;
- use app\models\SaasUserPriceLog;
- use app\modules\alliance\models\ShareQrcodeForm;
- use app\utils\Notice\NoticeAction;
- use GuzzleHttp\Psr7\Query;
- use yii\base\BaseObject;
- use yii\data\Pagination;
- use yii\helpers\Json;
- class ShareController extends BaseController
- {
- private $pageLimit = 10;
- public function behaviors()
- {
- return parent::behaviors();
- }
- /**
- * @return mixed|string
- * 绑定上下级关系
- */
- public function actionBindParent()
- {
- $parent_id = get_params('parent_id');
- if($parent_id > 0){
- $saas_user = get_saas_user();
- if($saas_user->parent_id > 0) {
- $data = [
- 'code' => 0,
- 'msg' => '用户已经有上级',
- ];
- } else {
- if ($parent_id == $saas_user->id) {
- $data = [
- 'code' => 0,
- 'msg' => '上级不能是自己',
- ];
- } else {
- $saas = SaasUser::findOne(['id' => $saas_user->id, 'is_delete' => 0]);
- $saas->parent_id = $parent_id;
- if ($saas->save()) {
- $data = [
- 'code' => 0,
- 'msg' => '绑定成功',
- ];
- } else {
- $data = [
- 'code' => 0,
- 'msg' => '绑定失败请稍后再试',
- ];
- }
- }
- }
- } else {
- $data = [
- 'code' => 0,
- 'msg' => '用户未找到',
- ];
- }
- return $this->asJson($data);
- }
- /**
- * 获取提现方式
- */
- public function actionGetCashMethod()
- {
- $saas_user = get_saas_user();
- $cash_method = [];
- if (!empty($saas_user->withdraw_method)) {
- $decode = json_decode($saas_user->withdraw_method, true);
- if (is_array($decode)) {
- $cash_method = $decode;
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $cash_method,
- ],
- ]);
- }
- /**
- * 删除提现方式
- */
- public function actionDelCashMethod()
- {
- $saas_user = get_saas_user();
- $type = post_params('type');
- if (empty($type)) {
- return $this->asJson([
- 'code' => 1,
- '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');
- if (empty($name) || empty($account)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '账号和姓名不能为空',
- ]);
- }
- if ($type == 'bank_card' && (empty($bank) || empty($branch))) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '银行或支行不能为空',
- ]);
- }
- $data = [
- 'type' => $type,
- 'name' => $name,
- 'account' => $account,
- ];
- if ($type == 'bank_card') {
- $data['bank'] = $bank;
- $data['branch'] = $branch;
- }
- $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' => '操作失败',
- ]);
- }
- /**
- * @return mixed|string
- * 获取佣金相关
- */
- public function actionGetPrice()
- {
- $saas_id = get_saas_user_id();
- $form = new ShareForm();
- $form->store_id = get_store_id();
- //$form->user_id = get_user_id();
- $form->saas_id = $saas_id;
- $res['data']['price'] = $form->getPrice();
- $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'];
- $cash_last = Cash::find()->where(['saas_id' => $saas_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 ($cash_max_day) {
- $cash_sum = Cash::find()->where([
- 'store_id' => get_store_id(),
- 'is_delete' => 0,
- 'status' => [0, 1, 2, 5],
- ])->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;
- }
- $cashServiceCharge = floatval($setting['cash_service_charge']['value']);
- $res['data']['cash_service_charge'] = $cashServiceCharge;
- if($cashServiceCharge == 0){
- $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
- // ],
- ];
- if(isset($res['data']['pay_type'])){
- foreach($res['data']['pay_type'] as $val){
- if($val == 'alipay'){
- $payTypeList[1]['is_show'] = true;
- }
- if($val == 'wechat'){
- $payTypeList[0]['is_show'] = true;
- }
- if($val == 'bank'){
- $payTypeList[2]['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(['saas_id' => $saas_id, 'is_delete' => 0])
- // ->orderBy('id desc')->asArray()->one();
- //新提现方式
- $res['data']['cash_method_list'] = [];
- $saas_user = get_saas_user();
- if (!empty($saas_user->withdraw_method)) {
- $cash_method = json_decode($saas_user->withdraw_method, true);
- if (is_array($cash_method)) {
- $res['data']['cash_method_list'] = $cash_method;
- }
- }
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res['data']]);
- }
- /**
- * @return mixed|string
- * 申请提现
- */
- public function actionApply()
- {
- $form = new CashForm();
- $form->saas_id = get_saas_user_id();
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->save());
- }
- /**
- * @return mixed|string
- * 申请提现
- */
- public function actionIndex()
- {
- $form = new ShareForm();
- return $this->asJson($form->getShareSetting());
- }
-
- /**
- * 提现明细列表
- */
- public function actionCashDetail()
- {
- $form = new CashListForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- $form->saas_id = get_saas_user_id();
- return $this->asJson($form->getList());
- }
- /**
- * @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->saas_id = get_saas_user_id();
- $form->scenario = "TEAM";
- $form->level = get_params('level',1);
- return $this->asJson($form->getTeam());
- }
-
- /**
- * @return mixed|string
- * 获取团队详情
- */
- public function actionGetTeamCount()
- {
- $form = new TeamForm();
- $form->attributes = get_params();
- $form->saas_id = get_saas_user_id();
- $form->scenario = "TEAM";
- $info = $form->getTeamCount();
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'data' => $info
- ];
- return $this->asJson($data);
- }
- /**
- * 推荐人列表
- * @return Response
- * @throws InvalidConfigException
- * @throws Throwable
- * @throws Exception
- */
- public function actionReferralList()
- {
- $status = get_params('status', 1);
- $saas_id = get_saas_user_id();
- $query = SaasStoreReferral::find()->alias('ssr')->leftJoin(['su' => SaasUser::tableName()], 'ssr.referral_id = su.id');
- $query->leftJoin(['s' => Store::tableName()], 'ssr.store_id = s.id');
- $query->where(['ssr.is_enable' => $status,'su.id'=>$saas_id]);
- $query->select('ssr.id, ssr.store_id, ssr.referral_id, ssr.is_enable, s.name as store_name,s.created_at,s.user_name,s.contact_tel ,s.logo, ssr.referral_rebate, su.avatar, su.name as nickname, su.mobile, su.id as saas_id');
- $list = pagination_make($query);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ]
- ]);
- }
- /**
- * 店铺分销订单
- */
- public function actionDistributionOrder(){
- $this->getOrderInfo(0);
- }
- /**
- * 推荐店铺订单
- */
- public function actionRecommendOrder(){
- $this->getOrderInfo(2);
- }
-
- /**
- * 会员分销订单
- */
- public function actionMemberOrder(){
- $this->getOrderInfo(1);
- }
- /**
- * 会员分销订单
- */
- public function actionSelfOrder(){
- $this->getOrderInfo(5);
- }
- /**
- * 灵活分润
- */
- public function actionCustomSharingOrder(){
- $this->getOrderInfo(6);
- }
- /**
- * 供货商分润订单(非分账)
- */
- public function actionSupplierOrder() {
- $saas_id = get_saas_user_id();
- $status = intval(get_params('status'));
- $query = SaasUserPriceLog::find()->alias('pl')
- ->leftJoin(['ot' => OrderTransit::tableName()],
- "pl.order_no LIKE 'PO%' AND pl.order_no = ot.cloud_order_no AND ot.is_delete = 0")
- ->leftJoin(['po' => PurchaseOrder::tableName()],
- "pl.order_no LIKE 'AP%' AND pl.order_no = po.order_no AND po.is_delete = 0")
- ->where([
- 'pl.saas_id' => $saas_id,
- 'pl.log_type' => SaasUserPriceLog::LOG_TYPE_INCOME,
- 'pl.amount_type' => SaasUserPriceLog::AMOUNT_TYPE_SUPPLIER_PARENT
- ]);
- if ($status === 1) {
- $query->andWhere(['OR', [//查询未完成的订单
- 'ot.status' => [-1, 0, 1]//取消 / 转单创建成功 / 已发货
- ], [
- 'po.trade_status' => [-1, 0, 1, 2]//默认 / 待发货 / 已取消 / 已发货
- ]]);
- }
- if ($status === 2) {
- $query->andWhere(['OR', [//查询未完成的订单
- 'ot.status' => 2//已确认收货
- ], [
- 'po.trade_status' => 3//已确认
- ]]);
- }
- $query->orderBy('pl.created_at DESC')->select([
- 'pl.id',
- 'pl.saas_id',
- 'pl.amount',
- 'pl.created_at',
- 'COALESCE(ot.cloud_order_no, po.order_no) AS order_no',
- 'COALESCE(ot.status, po.trade_status) AS trade_status',
- 'ot.goods_info'
- ]);
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $orderNoHead = substr($item['order_no'], 0, 2);
- $item['saasInfo'] = [
- 'name' => '',
- 'avatar' => ''
- ];
- if ($orderNoHead === 'PO') {
- $order_detail = [];
- $goods_info = json_decode($item['goods_info'], true);
- foreach ($goods_info as $goods_index => $goods_item) {
- $order_detail[$goods_index]['num'] = $goods_item['num'];
- $order_detail[$goods_index]['attr'] = $goods_item['attr'];
- $order_detail[$goods_index]['total_price'] = $goods_item['price'];
- $order_detail[$goods_index]['pic'] = $goods_item['pic_url'];
- $order_detail[$goods_index]['goods_name'] = $goods_item['goods_name'] ?: '';
- }
- if (intval($item['trade_status']) === -1) {
- $item['trade_status'] = 1;
- }
- if (intval($item['trade_status']) === 1) {
- $item['trade_status'] = 2;
- }
- if (intval($item['trade_status']) === 2) {
- $item['trade_status'] = 3;
- }
- $orderTransit = OrderTransit::findOne(['cloud_order_no' => $item['order_no'], 'is_delete' => 0]);
- $order = Order::findOne($orderTransit->order_id);
- if ($order->saas_id) {
- $saasInfo = SaasUser::findOne($order->saas_id);
- $item['saasInfo'] = [
- 'name' => $saasInfo->name,
- 'avatar' => $saasInfo->avatar
- ];
- } else {
- $userInfo = User::findOne($order->user_id);
- if ($userInfo->binding) {
- $saasInfo = SaasUser::findOne(['mobile' => $userInfo->binding, 'is_delete' => 0]);
- $item['saasInfo'] = [
- 'name' => $saasInfo->name,
- 'avatar' => $saasInfo->avatar
- ];
- }
- }
- } else {
- $purchaseOrder = PurchaseOrder::findOne(['order_no' => $item['order_no'], 'is_delete' => 0]);
- $order_detail = PurchaseOrderDetail::find()->where(['order_id' => $purchaseOrder->id, 'is_delete' => 0])
- ->select('goods_name, num, pic, total_price, attr')->asArray()->all();
- if(!empty($purchaseOrder->saas_id)){
- $saasInfo = SaasUser::find()->where(['id' => $purchaseOrder['saas_id'], 'is_delete'=>0])
- ->select('name, avatar')->asArray()->one();
- $item['saasInfo'] = $saasInfo;
- }
- }
- foreach ($order_detail as &$order_detail_item) {
- $order_detail_item['attr'] = json_decode($order_detail_item['attr'], true);
- }
- $item['goods'] = $order_detail;
- $item['trade_status'] = intval($item['trade_status']);
- $item['status'] = 1;
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ]
- ]);
- }
- //
- private function getOrderInfo($from = 0){
- $status = get_params('status',0);
- $page = get_params('page',1);
- //会员分销订单
- $saas_id = get_saas_user_id();
- $saasIds = SaasUser::find()->where(['parent_id'=>$saas_id])->asArray()->all();
- $levelSaasIds = '';
- if(!empty($saasIds) && count($saasIds) > 0) {
- foreach($saasIds as $val){
- $levelSaasIds .= $val['id'].',';
- }
- }
- $levelSaasIds .= $saas_id;
-
- $sql_count = "select count(o.order_no) num from `cyy_sharing_receiver` as s inner join ( ( select id order_id,order_no,trade_status,is_pay,pay_type from cyy_order ) union (select id order_id,order_no,trade_status,is_pay,pay_type from cyy_scan_code_pay_order ) ) as o on s.`order_no`= o.`order_no` where s.saas_id={$saas_id} ";
- $sql = "select o.*,s.amount, s.is_pay as status from `cyy_sharing_receiver` as s inner join ( ( select id order_id,order_no,trade_status,is_pay,pay_type,saas_id,0 as order_type, created_at from cyy_order ) union (select id order_id,order_no,trade_status,is_pay,pay_type,saas_id,1 as order_type, created_at from cyy_scan_code_pay_order ) ) as o on s.`order_no`= o.`order_no` where s.saas_id={$saas_id} ";
-
- if(in_array($from, [
- SharingReceiver::FROM_STORE,
- SharingReceiver::FROM_PLATFORM,
- SharingReceiver::FROM_RECOMMEND,
- SharingReceiver::FROM_SELF,
- SharingReceiver::FROM_CUSTOM
- ])){
- $sql_count .= " and s.from = {$from}";
- $sql .= " and s.from = {$from}";
- }
- // if ($status == 1) {//待付款
- // $is_pay = Order::IS_PAY_FALSE;
- // $sql_count .= " and o.is_pay = {$is_pay} and o.pay_type !=2 and o.trade_status !=1";
- // $sql .= " and o.is_pay = {$is_pay} and o.pay_type !=2 and o.trade_status !=1";
- // }
- if ($status == 1) {//已付款
- $trade_status = Order::ORDER_FLOW_NO_SEND;
- $sql_count .= " and o.trade_status = {$trade_status} and o.is_pay = 1";
- $sql .= " and o.trade_status = {$trade_status} and o.is_pay = 1";
- }
- if ($status == 2) {//已完成
- $trade_status = Order::ORDER_FLOW_CONFIRM;
- $sql_count .= " and o.trade_status = {$trade_status} and o.is_pay = 1";
- $sql .= " and o.trade_status = {$trade_status} and o.is_pay = 1";
- }
- $connection_count = \Yii::$app->db;
- $command_count = $connection_count->createCommand($sql_count);
- $info = $command_count->queryOne();
- $start = ($page - 1) * $this->pageLimit;
- $sql .= " limit {$start} , {$this->pageLimit} ";
- $command = $connection_count->createCommand($sql);
- $list['list'] = $command->queryAll();
- $list['pageNo'] = $page;
- $list['totalCount'] = $info['num'];
- if(count($list['list']) > 0 ){
- foreach($list['list'] as $key=>$val){
- if(isset($val['order_id']) && !empty($val['order_id']) ){
- $orderNoHead = substr($val['order_no'], 0, 2);
- if($orderNoHead == 'SC'){
- $list['list'][$key]['goods'] = [
- [
- "goods_id" => '10',
- "goods_name" => '扫码支付',
- "num" => '1',
- "pic" => '',
- "goods_info" => null,
- "total_price" => '',
- ]
- ];
- }else{
- $goodsInfo = OrderDetail::find()->where(['order_id' => $val['order_id'], 'is_delete' => 0])->select('goods_id, goods_name, num, pic, attr, total_price')->asArray()->all();
- foreach ($goodsInfo as &$goods_item) {
- $goods_item['attr'] = json_decode($goods_item['attr'], true);
- }
- $list['list'][$key]['goods'] = $goodsInfo;
- }
- }
- if(isset($val['saas_id']) && $val['saas_id'] > 0){
- $saasInfo = SaasUser::find()->where(['id'=>$val['saas_id'],'is_delete'=>0])->select('name,avatar')->asArray()->one();
- $list['list'][$key]['saasInfo'] = $saasInfo;
- }
- $list['list'][$key]['status'] = intval($val['status']) ? 1 : 0;
- $list['list'][$key]['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ]
- ]);
- }
- /**
- * 下级供货商
- */
- public function actionSubSupplier(){
- $saas_id = get_saas_user_id();
- $query = SaasSupplierReferral::find()->alias('ssr')
- ->leftJoin(['s' => Supplier::tableName()], 'ssr.supplier_id = s.id')
- ->where(['ssr.referral_id' => $saas_id, 's.is_delete' => 0])
- ->andWhere(['IS NOT', 's.id', NULL])
- ->select('ssr.supplier_id, ssr.referral_rebate, ssr.is_enable');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $supplier = Supplier::findOne($item['supplier_id']);
- $item['supplier_name'] = $supplier->supplier_name;
- $item['logo'] = $supplier->logo;
- $item['is_enable'] = intval($item['is_enable']);
- $item['created_at'] = $item['created_at'] > 0 ? date('Y-m-d H:i:s', $item['created_at']) : '';
- $item['amount'] = SaasUserPriceLog::find()->where([
- 'log_type' => SaasUserPriceLog::LOG_TYPE_INCOME,
- 'amount_type' => SaasUserPriceLog::AMOUNT_TYPE_SUPPLIER_PARENT,
- 'supplier_id' => $item['supplier_id']
- ])->sum('amount') ?: 0;
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ]
- ]);
- }
- /**
- * 会员卡
- */
- public function actionBusinessOrder(){
- $saas_id = get_saas_user_id();
- // $saasIds = SaasUser::find()->where(['parent_id'=>$saas_id])->select('id')->asArray()->all();
- // var_dump($saasIds);exit;
- // if(!empty($saasIds) && count($saasIds)>0 ){
- $query = SaasShareMoney::find()->alias('s')->where(['s.saas_id'=> $saas_id,'s.is_delete'=>0]);
- $query->leftJoin(['o' => BusinessMemberOrder::tableName()], 'o.id = s.order_id');
- $query->select('o.saas_id,o.id order_id,o.member_id,o.pay_price,s.money,o.created_at');
- $list = pagination_make($query);
- if(count($list['list']) > 0 ){
- foreach($list['list'] as $key=>$val){
- if(isset($val['member_id']) && $val['member_id'] > 0 ){
- $businessInfo = BusinessMember::findOne($val['member_id']);
- if($businessInfo['is_delete']==0){
- $list['list'][$key]['businessInfo'] = $businessInfo;
- }else{
- $list['list'][$key]['businessInfo'] = [];
- }
- }
- if(isset($val['saas_id']) && $val['saas_id'] > 0){
- $saasInfo = SaasUser::find()->where(['id'=>$val['saas_id'],'is_delete'=>0])->select('name,avatar')->asArray()->one();
- $list['list'][$key]['saasInfo'] = $saasInfo;
- }
- }
- }
- $data['data'] = $list['list'];
- $data['pageNo'] = $list['pageNo'];
- $data['totalCount'] = $list['totalCount'];
- // }else{
- // $data['data'] = [];
- // $data['pageNo'] = 0;
- // $data['totalCount'] = 0;
- // }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- }
- /**
- * 结算明细
- */
- public function actionDetailedOrder(){
- $status = get_params('status',0);
- //会员分销订单
- $saas_id = get_saas_user_id();
- //$saas_id = 533;
- $store_share_type = implode(',', [
- SharingReceiver::FROM_AREA_AGENT_PROVIDER,
- SharingReceiver::FROM_AREA_AGENT_CITY,
- SharingReceiver::FROM_AREA_AGENT_DISTRICT,
- SharingReceiver::FROM_BD_AGENT
- ]);
- $query = SharingReceiver::find()->alias('sr')->where(['sr.is_delete' => 0])
- ->leftJoin(['o' => Order::tableName()], 'sr.order_no = o.order_no AND o.is_delete = 0')
- ->leftJoin(['sup' => SaasUserPriceLog::tableName()], "sr.order_no = sup.order_no AND sup.saas_id = {$saas_id}")
- ->leftJoin(['ssm' => StoreShareMoney::tableName()], "o.id = ssm.order_id AND sr.from in ({$store_share_type}) AND ssm.user_id = {$saas_id} ")
- ->andWhere(['sr.saas_id' => $saas_id])
- ->select('sr.id as sr_id, sr.order_no, sr.from, sup.log_type, sup.desc remark, sup.amount, sr.created_at, sup.created_at updated_at, sr.is_pay, sr.amount sharing_amount, sr.remark sharing_remark');
- if ($status == 1) {//未到账
- $query->andWhere([
- 'sr.is_pay' => [0, 2]
- ]);
- }
- if ($status == 2) {//已到账
- $query->andWhere([
- 'sr.is_pay' => 1
- ]);
- }
- $query->groupBy(new \yii\db\Expression("IF(sr.from IN (7, 8), IFNULL(ssm.id, 'default'), IFNULL(sup.id, 'default'))"))
- ->orderBy(new \yii\db\Expression("IF(sr.from IN (7, 8), IFNULL(ssm.id, 'default'), IFNULL(sup.id, 'default')) DESC"));
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- if (!isset($item['log_type'])) {
- $item['log_type'] = 1;
- }
- if (!isset($item['remark'])) {
- $item['remark'] = $item['sharing_remark'];
- }
- if (!isset($item['amount'])) {
- $item['amount'] = $item['sharing_amount'];
- }
- $item['log_type'] = intval($item['log_type']);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ]
- ]);
- }
- //佣金明细
- public function actionPriceLog() {
- $log_type = get_params('log_type', 0);
- $saas_id = get_saas_user_id();
- $query = SaasUserPriceLog::find()->where(['saas_id' => $saas_id]);
- if($log_type){
- $query->andWhere(['log_type' => $log_type]);
- }
- $query->orderBy('id DESC');
- $list = pagination_make($query);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ]
- ]);
- }
- /**
- * @return mixed|string
- * 获取推广海报
- */
- public function actionGetQrcode()
- {
- $form = new ShareQrcodeForm();
- $form->type = 4;
- $form->user = get_user();
- $form->user_id = get_user_id();
- $form->saas_id = get_saas_user_id();
- $form->store_id = -1;
- return $this->asJson($form->search());
- }
- }
|