ShareController.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\controllers\v1;
  8. use app\constants\OptionSetting;
  9. use app\models\Cash;
  10. use app\models\CashExt;
  11. use app\models\IntegralAppreciationPool;
  12. use app\models\IntegralAppreciationUser;
  13. use app\models\Level;
  14. use app\models\LevelOrder;
  15. use app\models\Lg;
  16. use app\models\Md;
  17. use app\models\Option;
  18. use app\models\Order;
  19. use app\models\OrderDetail;
  20. use app\models\OrderRefund;
  21. use app\models\RcCommissionLog;
  22. use app\models\ReOrder;
  23. use app\models\SaasUser;
  24. use app\models\Share;
  25. use app\models\ShareDetail;
  26. use app\models\ShareGroupPurchaseUser;
  27. use app\models\ShareLevel;
  28. use app\models\Store;
  29. use app\models\SuperSalesUser;
  30. use app\models\TeamGrades;
  31. use app\models\User;
  32. use app\models\UserShareLog;
  33. use app\models\UserShareMoney;
  34. use app\models\VideoGoodsShare;
  35. use app\modules\client\behaviors\Auth;
  36. use app\modules\client\controllers\BaseController;
  37. use app\modules\client\models\TestForm;
  38. use app\modules\client\models\v1\BindForm;
  39. use app\modules\client\models\v1\CashForm;
  40. use app\modules\client\models\v1\CashListForm;
  41. use app\modules\client\models\v1\RcCommissionForm;
  42. use app\modules\client\models\v1\ShareCustomForm;
  43. use app\modules\client\models\v1\ShareForm;
  44. use app\modules\client\models\v1\ShareQrcodeForm;
  45. use app\modules\client\models\v1\TeamForm;
  46. use app\utils\Notice\NoticeAction;
  47. use yii\base\BaseObject;
  48. use yii\data\Pagination;
  49. use yii\helpers\Json;
  50. class ShareController extends BaseController
  51. {
  52. public function behaviors()
  53. {
  54. return parent::behaviors();
  55. }
  56. /**
  57. * @return mixed|string
  58. * 申请成为分销商
  59. */
  60. public function actionJoin()
  61. {
  62. $share = Share::findOne(['user_id' => get_user_id(),
  63. 'store_id' => get_store_id(), 'is_delete' => 0]);
  64. if (!$share) {
  65. $share = new Share();
  66. }
  67. $setting = Option::get('share_basic_setting', $this->store_id);
  68. $share_setting = $setting ? Json::decode($setting['value']) : [];
  69. $form = new ShareForm();
  70. $form->share = $share;
  71. $form->store_id = get_store_id();
  72. $form->attributes = post_params();
  73. if ($share_setting['share_condition']['value'] == 1) {
  74. $form->scenario = "APPLY";
  75. } elseif ($share_setting['share_condition']['value'] == 0 || $share_setting['share_condition']['value'] == 2) {
  76. $form->agree = 1;
  77. }
  78. return $this->asJson($form->save());
  79. }
  80. /**
  81. * @return mixed|string
  82. * 获取用户的审核状态
  83. */
  84. public function actionCheck()
  85. {
  86. return $this->asJson([
  87. 'code' => 0,
  88. 'msg' => 'success',
  89. 'data' => get_user()->is_distributor,
  90. 'level' => get_user()->level,
  91. 'template_id' => NoticeAction::getSendTamplateId(['share_examine'])
  92. ]);
  93. }
  94. /**
  95. * 获取分销中心数据
  96. * @return \yii\web\Response
  97. * @throws \yii\db\Exception
  98. */
  99. public function actionGetInfo()
  100. {
  101. if (get_user()->is_distributor != 1) {
  102. $data = [
  103. 'is_distributor' => get_user()->is_distributor
  104. ];
  105. $not_is_distributor = 0;
  106. $setting = Option::get('share_basic_setting', $this->store_id);
  107. $share_basic_setting = $setting ? Json::decode($setting['value']) : [];
  108. if (in_array((int)$share_basic_setting['share_condition']['value'], [0, 1])) {
  109. $not_is_distributor = 1;
  110. return $this->asJson([
  111. 'code' => 0,
  112. 'msg' => '您还不是分销商',
  113. 'not_is_distributor' => $not_is_distributor
  114. ]);
  115. }
  116. }
  117. $res = [
  118. 'code' => 0,
  119. 'msg' => 'success',
  120. ];
  121. $store_id = get_store_id();
  122. //获取分销佣金及提现
  123. $form = new ShareForm();
  124. $form->store_id = $store_id;
  125. $form->user_id = get_user()->id;
  126. $res['data']['price'] = $form->getPrice(0);
  127. //获取我的团队
  128. $team = new TeamForm();
  129. $team->user_id = get_user_id();
  130. $team->store_id = $store_id;
  131. $arr = $team->getOrderCount();
  132. $res['data']['team_count'] = get_user_id() ? $arr['team_count'] : 0;
  133. $res['data']['order_money'] = get_user_id() ? $arr['order_money'] : 0;
  134. $res['data']['order_money_un'] = get_user_id() ? $arr['order_money_un'] : 0;
  135. $res['data']['order_count'] = get_user_id() ? intval($arr['order_count']): 0;
  136. $res['data']['share_order_count'] = get_user_id() ? intval($arr['share_order_count']) : 0;
  137. $team->yinbao = 1;
  138. $arr = $team->getOrderCount();
  139. $res['data']['order_count_yinbao'] = get_user_id() ? intval($arr['order_count']) : 0;
  140. //获取分销商等级
  141. $share = Share::findOne(['store_id' => $store_id, 'user_id' => get_user_id(), 'is_delete' => 0]);
  142. $res['data']['level_name'] = '-';
  143. if ($share) {
  144. $share_level = ShareLevel::findOne(['level' => $share->level, 'store_id' => $store_id, 'is_delete' => 0]);
  145. if ($share_level) {
  146. $res['data']['level_name'] = $share_level->name;
  147. }
  148. }
  149. $shareOption = Option::findOne([
  150. 'store_id' => $store_id,
  151. 'group' => OptionSetting::SHARE_GROUP_NAME,
  152. 'name' => OptionSetting::SHARE_BASIC_SETTING
  153. ]);
  154. $shareOption = Json::decode($shareOption['value']);
  155. $res['data']['video_share_order_count'] = VideoGoodsShare::find()->where(['author_user_id' => get_user_id()])->groupBy('order_id')->count();
  156. $res['data']['wx_title'] = $shareOption['wx_title']['value'] ?: '分销中心';
  157. //获取分销自定义数据
  158. // $custom_form = new ShareCustomForm();
  159. // $custom_form->store_id = $store_id;
  160. // $custom = $custom_form->getData();
  161. // $res['data']['custom'] = $custom['data'];
  162. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res['data']]);
  163. }
  164. /**
  165. * @return mixed|string
  166. * 获取佣金相关
  167. */
  168. public function actionGetPrice()
  169. {
  170. $form = new ShareForm();
  171. $form->store_id = get_store_id();
  172. $form->user_id = get_user_id();
  173. $is_team_grades = intval(get_params('is_team_grades'));
  174. $is_share_group_purchase = intval(get_params('is_share_group_purchase'));
  175. $is_super_sales = intval(get_params('is_super_sales'));
  176. $is_integral_appreciation = intval(get_params('is_integral_appreciation'));
  177. $res['data']['price'] = $form->getPrice();
  178. if ($is_team_grades) {
  179. $userTeamGrades = TeamGrades::getUserTeamGrades(get_user_id());
  180. if ($res['data']['price']['price'] > $userTeamGrades['price']) {
  181. $res['data']['price']['price'] = $userTeamGrades['price'];
  182. }
  183. $setting = Option::get('share_basic_setting', get_store_id());
  184. $setting = $setting ? Json::decode($setting['value']) : [];
  185. $res['data']['pay_type'] = 2;
  186. $res['data']['bank'] = 1;
  187. $res['data']['remaining_sum'] = 0;
  188. } elseif ($is_share_group_purchase) {
  189. $shareGroupPurchaseUser = ShareGroupPurchaseUser::findOne(['user_id' => get_user_id()]);
  190. if ($res['data']['price']['price'] > $shareGroupPurchaseUser->price) {
  191. $res['data']['price']['price'] = $shareGroupPurchaseUser->price;
  192. }
  193. $setting = Option::get('share_group_setting', get_store_id());
  194. $setting = $setting ? Json::decode($setting['value']) : [];
  195. $res['data']['pay_type'] = $setting['pay_type'] ?: 0;
  196. $res['data']['bank'] = $setting['bank'] ?: 0;
  197. $res['data']['lg'] = $setting['lg'] ?: 0;
  198. $res['data']['remaining_sum'] = $setting['remaining_sum'] ?: 0;
  199. } elseif ($is_super_sales) {
  200. $superSalesUser = SuperSalesUser::findOne(['user_id' => get_user_id()]);
  201. if ($res['data']['price']['price'] > $superSalesUser->price) {
  202. $res['data']['price']['price'] = $superSalesUser->price;
  203. }
  204. $setting = Option::get('super_sales_setting', get_store_id());
  205. $setting = $setting ? Json::decode($setting['value']) : [];
  206. $res['data']['pay_type'] = $setting['pay_type'] ?: 0;
  207. $res['data']['bank'] = $setting['bank'] ?: 0;
  208. $res['data']['lg'] = $setting['lg'] ?: 0;
  209. $res['data']['remaining_sum'] = $setting['remaining_sum'] ?: 0;
  210. } elseif ($is_integral_appreciation) {
  211. $integralAppreciationUser = IntegralAppreciationUser::findOne(['user_id' => get_user_id()]);
  212. //与其他不一样 增值积分需要先根据提现金额 计算一下实际的提现金额
  213. $res['data']['price']['price'] = $integralAppreciationUser->integral ?: '0.00';
  214. $setting = Option::get('integral_appreciation_setting', get_store_id());
  215. $setting = $setting ? Json::decode($setting['value']) : [];
  216. // $integralAppreciationPool = IntegralAppreciationPool::findOne(['store_id' => get_store_id()]);
  217. // $integral_price = $integralAppreciationPool->integral_price ?: ($setting['integral_init_price'] ?: 0);
  218. $res['data']['integral_custom_name'] = $setting['integral_custom_name'] ?: '增值积分';
  219. $res['data']['pay_type'] = $setting['pay_type'] ?: 0;
  220. $res['data']['bank'] = $setting['bank'] ?: 0;
  221. $res['data']['lg'] = $setting['lg'] ?: 0;
  222. $res['data']['remaining_sum'] = $setting['remaining_sum'] ?: 0;
  223. } else {
  224. $setting = Option::get('share_basic_setting', get_store_id());
  225. $setting = $setting ? Json::decode($setting['value']) : [];
  226. $res['data']['pay_type'] = $setting['pay_type']['value'];
  227. $res['data']['bank'] = $setting['bank']['value'];
  228. $res['data']['lg'] = $setting['lg']['value'];
  229. $res['data']['remaining_sum'] = $setting['remaining_sum']['value'];
  230. }
  231. $cash_last = Cash::find()->where(['store_id' => get_store_id(), 'user_id' => get_user_id(), 'is_delete' => 0])
  232. ->orderBy(['id' => SORT_DESC])->select(['name', 'mobile', 'type', 'bank_name'])->asArray()->one();
  233. $res['data']['cash_last'] = $cash_last;
  234. $cash_max_day = floatval($setting['cash_max_day']['value']);
  235. if ($is_share_group_purchase || $is_super_sales) {
  236. $cash_max_day = floatval($setting['cash_max_day']);
  237. }
  238. if ($cash_max_day && !$is_team_grades) {
  239. $query = Cash::find()->where([
  240. 'store_id' => get_store_id(),
  241. 'is_delete' => 0,
  242. 'status' => [0, 1, 2, 5],
  243. ]);
  244. if ($is_share_group_purchase) {
  245. $query->andWhere(['cash_type' => Cash::IS_CASH_TYPE_SHARE_GROUP_PURCHASE]);
  246. } elseif ($is_super_sales) {
  247. $query->andWhere(['cash_type' => Cash::IS_CASH_TYPE_SUPER_SALES]);
  248. } else {
  249. $query->andWhere(['cash_type' => Cash::IS_CASH_TYPE_SHARE]);
  250. }
  251. $cash_sum = $query->andWhere([
  252. 'AND',
  253. ['>=', 'created_at', strtotime(date('Y-m-d 00:00:00'))],
  254. ['<=', 'created_at', strtotime(date('Y-m-d 23:59:59'))],
  255. ])->sum('price');
  256. $cash_max_day = $cash_max_day - ($cash_sum ? $cash_sum : 0);
  257. $res['data']['cash_max_day'] = max(0, floatval(sprintf('%.2f', $cash_max_day)));
  258. } else {
  259. $res['data']['cash_max_day'] = -1;
  260. }
  261. if ($res['data']['cash_max_day'] !== 0) {
  262. $cash_max_single_day = $setting['cash_max_single_day']['value'];
  263. if ($is_share_group_purchase) {
  264. $cash_max_single_day = $setting['cash_max_single_day'];
  265. }
  266. if ($cash_max_single_day) { //cash_max_day = 2 cash_max_single_day = 3 2
  267. // 3 2
  268. if ($res['data']['cash_max_day'] > $cash_max_single_day) {
  269. $res['data']['cash_max_day'] = $cash_max_single_day;
  270. }
  271. } else {
  272. $res['data']['cash_max_day'] = -1;
  273. }
  274. }
  275. $cashServiceCharge = floatval($setting['cash_service_charge']['value']);
  276. $res['data']['cash_service_charge'] = $cashServiceCharge;
  277. if ($is_share_group_purchase) {
  278. $cashServiceCharge = floatval($setting['cash_service_charge']);
  279. $res['data']['cash_service_charge'] = $cashServiceCharge;
  280. }
  281. if($cashServiceCharge == 0 || $is_team_grades){
  282. $res['data']['service_content'] = "";
  283. }else{
  284. $res['data']['service_content'] = "提现需要加收{$cashServiceCharge}%手续费";
  285. }
  286. $wxappUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/wxapp/images';
  287. $payTypeList = [
  288. [
  289. 'icon' => $wxappUrl . '/icon-share-wechat.png',
  290. 'name' => '微信',
  291. 'is_show' => false
  292. ],
  293. [
  294. 'icon' => $wxappUrl . '/icon-share-ant.png',
  295. 'name' => '支付宝',
  296. 'is_show' => false
  297. ],
  298. [
  299. 'icon' => $wxappUrl . '/icon-share-bank.png',
  300. 'name' => '银行卡',
  301. 'is_show' => false
  302. ],
  303. [
  304. 'icon' => $wxappUrl . '/gold.png',
  305. 'name' => '余额',
  306. 'is_show' => false
  307. ],
  308. [
  309. 'icon' => $wxappUrl . '/icon-share-bank.png',
  310. 'name' => '灵工提现',
  311. 'is_show' => false
  312. ],
  313. ];
  314. switch($res['data']['pay_type']){
  315. case 0:
  316. $payTypeList[0]['is_show'] = true;
  317. break;
  318. case 1:
  319. $payTypeList[1]['is_show'] = true;
  320. break;
  321. case 2:
  322. $payTypeList[0]['is_show'] = true;
  323. $payTypeList[1]['is_show'] = true;
  324. break;
  325. default:
  326. break;
  327. }
  328. if($res['data']['bank'] && $res['data']['bank'] == 1){
  329. $payTypeList[2]['is_show'] = true;
  330. }
  331. //灵工提现
  332. if($res['data']['lg'] && $res['data']['lg'] == 1){
  333. $payTypeList[4]['is_show'] = true;
  334. }
  335. if($res['data']['remaining_sum'] && $res['data']['remaining_sum'] == 1){
  336. $payTypeList[3]['is_show'] = true;
  337. }
  338. $res['data']['pay_type_list'] = $payTypeList;
  339. $res['data']["cash_success_tpl"] = '';
  340. $res['data']["cash_fail_tpl"]= '';
  341. //获取分销订单
  342. $res['data']['fx_list'] = Cash::find()->Where(['user_id' => get_user_id(), 'store_id' => get_store_id()])
  343. ->orderBy('id desc')->asArray()->one();
  344. // 新提现方式
  345. $res['data']['cash_method_list'] = [];
  346. $saas_user = get_saas_user();
  347. $cash_method = [];
  348. if (!empty($saas_user->withdraw_method)) {
  349. $cash_method = json_decode($saas_user->withdraw_method, true);
  350. }
  351. $money = [
  352. [
  353. 'type' => 'money'
  354. ]
  355. ];
  356. $cash_method = array_merge($cash_method, $money);
  357. //判断是否灵工进件
  358. $lg_info = Lg::find()->where(['user_id' => $saas_user->id, 'store_id' => get_store_id(),'status'=>1,'is_delete'=>0])->one();
  359. if ($lg_info){
  360. $lg = [
  361. [
  362. 'type' => 'lg'
  363. ]
  364. ];
  365. $cash_method = array_merge($cash_method, $lg);
  366. }
  367. if (is_array($cash_method)) {
  368. foreach ($cash_method as $index => &$item) {
  369. if ($item['type'] === 'wechat' && $payTypeList[0]['is_show'] === false) {
  370. unset($cash_method[$index]);
  371. }
  372. if ($item['type'] === 'alipay' && $payTypeList[1]['is_show'] === false) {
  373. unset($cash_method[$index]);
  374. }
  375. if ($item['type'] === 'bank_card' && $payTypeList[2]['is_show'] === false) {
  376. unset($cash_method[$index]);
  377. }
  378. if ($item['type'] === 'money' && $payTypeList[3]['is_show'] === false) {
  379. unset($cash_method[$index]);
  380. }
  381. if ($item['type'] === 'lg' && $payTypeList[4]['is_show'] === false) {
  382. unset($cash_method[$index]);
  383. }
  384. }
  385. $res['data']['cash_method_list'] = array_values($cash_method);;
  386. }
  387. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res['data']]);
  388. }
  389. /**
  390. * 获取提现方式
  391. */
  392. public function actionGetCashMethod()
  393. {
  394. $saas_user = get_saas_user();
  395. $cash_method = [];
  396. $payTypeList = [
  397. [
  398. 'name' => '微信',
  399. 'is_show' => false,
  400. 'type' => 'wechat',
  401. 'is_bind' => false
  402. ],
  403. [
  404. 'name' => '支付宝',
  405. 'is_show' => false,
  406. 'type' => 'alipay',
  407. 'is_bind' => false
  408. ],
  409. [
  410. 'name' => '银行卡',
  411. 'is_show' => false,
  412. 'type' => 'bank_card',
  413. 'is_bind' => false
  414. ],
  415. [
  416. 'name' => '灵工提现',
  417. 'is_show' => false,
  418. 'type' => 'lg',
  419. 'is_bind' => false
  420. ],
  421. ];
  422. if (get_params('is_share_recharge') || get_params('is_share_group_purchase') || get_params('is_super_sales') || get_params('is_integral_appreciation')) {
  423. $setting = Option::get('share_basic_setting', get_store_id());
  424. $setting = $setting ? Json::decode($setting['value']) : [];
  425. $res['data']['pay_type'] = $setting['pay_type']['value'];
  426. $res['data']['bank'] = $setting['bank']['value'];
  427. $res['data']['remaining_sum'] = $setting['remaining_sum']['value'];
  428. $res['data']['lg'] = $setting['lg']['value'];
  429. if (intval(get_params('is_share_group_purchase')) || intval(get_params('is_super_sales')) || intval(get_params('is_integral_appreciation'))) {
  430. if (intval(get_params('is_share_group_purchase'))) {
  431. $setting = Option::get('share_group_setting', get_store_id());
  432. } elseif (intval(get_params('is_integral_appreciation'))) {
  433. $setting = Option::get('integral_appreciation_setting', get_store_id());
  434. } else {
  435. $setting = Option::get('super_sales_setting', get_store_id());
  436. }
  437. $setting = $setting ? Json::decode($setting['value']) : [];
  438. $res['data']['pay_type'] = $setting['pay_type'];
  439. $res['data']['bank'] = $setting['bank'];
  440. $res['data']['remaining_sum'] = $setting['remaining_sum'];
  441. $res['data']['lg'] = $setting['lg'];
  442. }
  443. switch($res['data']['pay_type']){
  444. case 0:
  445. $payTypeList[0]['is_show'] = true;
  446. break;
  447. case 1:
  448. $payTypeList[1]['is_show'] = true;
  449. break;
  450. case 2:
  451. $payTypeList[0]['is_show'] = true;
  452. $payTypeList[1]['is_show'] = true;
  453. break;
  454. default:
  455. break;
  456. }
  457. if($res['data']['bank'] && $res['data']['bank'] == 1){
  458. $payTypeList[2]['is_show'] = true;
  459. }
  460. if($res['data']['lg'] && $res['data']['lg'] == 1){
  461. $payTypeList[3]['is_show'] = true;
  462. }
  463. } elseif (intval(get_params('is_rider'))) {//骑手配置
  464. $local_type = Option::get(OptionSetting::STORE_LOCAL_TYPE, get_store_id(), 'store')['value'];
  465. $local_type = Option::get(OptionSetting::STORE_LOCAL_TYPE, get_store_id(), 'pay', $local_type);
  466. $store_id = $local_type['value'] === 'self_store' ? get_store_id() : 0;
  467. $setting = Option::get(OptionSetting::LOCAL_DELIVERY_SETTING, $store_id, OptionSetting::LOCAL_DELIVERY_GROUP_NAME, '')['value'];
  468. $setting = $setting ? Json::decode($setting) : [];
  469. if (!empty($setting['pay_type']['value'])) {
  470. foreach ($payTypeList as &$item) {
  471. if ($item['type'] === 'bank_card') {
  472. $type = "bank";
  473. } else {
  474. $type = $item['type'];
  475. }
  476. if (in_array($type, $setting['pay_type']['value'])) {
  477. $item['is_show'] = 1;
  478. }
  479. }
  480. }
  481. unset($item);
  482. } elseif (intval(get_params('is_team_grades'))) {//团队业绩分红
  483. foreach ($payTypeList as &$item) {
  484. $item['is_show'] = true;
  485. }
  486. unset($item);
  487. } else {
  488. $balanceToCashSet = json_decode(Option::get(OptionSetting::BALANCE_TO_CASH_SETTING, $this->store_id, 'recharge', '')['value'], true);
  489. if (!empty($balanceToCashSet)) {
  490. $balance_to_cash_pay_type = $balanceToCashSet['balance_to_cash_pay_type'];
  491. $store = Store::findOne($this->store_id);
  492. foreach ($payTypeList as &$item) {
  493. foreach ($balance_to_cash_pay_type as $type_index => $type_item) {
  494. if ($type_index === $item['type']) {
  495. if (intval($type_item) === 1) {
  496. $item['is_show'] = true;
  497. }
  498. }
  499. }
  500. if ('lg' === $item['type'] && $store->lg_cash) {
  501. $item['is_show'] = true;
  502. }
  503. }
  504. }
  505. unset($item);
  506. }
  507. if (!empty($saas_user->withdraw_method)) {
  508. $decode = json_decode($saas_user->withdraw_method, true);
  509. if (is_array($decode)) {
  510. $cash_method = $decode;
  511. foreach ($payTypeList as &$pay_item) {
  512. foreach ($cash_method as $item) {
  513. if ($item['type'] === $pay_item['type']) {
  514. $pay_item['is_bind'] = true;
  515. $pay_item = array_merge($pay_item, $item);
  516. }
  517. }
  518. }
  519. }
  520. }
  521. //判断灵工是否绑定
  522. foreach ($payTypeList as &$item){
  523. $lg = Lg::find()->where(['user_id' => $saas_user->id,'is_delete'=>0,'status'=>1])->one();
  524. if ($lg){
  525. if ('lg' === $item['type']) {
  526. $item['is_bind'] = true;
  527. $item = array_merge($item, $item);
  528. }
  529. }
  530. }
  531. return $this->asJson([
  532. 'code' => 0,
  533. 'msg' => 'success',
  534. 'data' => [
  535. 'list' => $payTypeList,
  536. ],
  537. ]);
  538. }
  539. /**
  540. * 获取提现方式
  541. */
  542. public function actionDelCashMethod()
  543. {
  544. $saas_user = get_saas_user();
  545. $type = post_params('type');
  546. if (empty($type)) {
  547. return $this->asJson([
  548. 'code' => 1,
  549. 'msg' => '参数错误',
  550. ]);
  551. }
  552. if ($type == 'lg'){
  553. $lg = Lg::find()->where(['user_id'=>$saas_user->id,'is_delete'=>0])->one();
  554. if ($lg){
  555. $lg->is_delete = 1;
  556. $lg->save();
  557. return $this->asJson([
  558. 'code' => 0,
  559. 'msg' => '操作成功',
  560. ]);
  561. }
  562. }
  563. if (empty($saas_user->withdraw_method)) {
  564. return $this->asJson([
  565. 'code' => 0,
  566. 'msg' => '操作成功',
  567. ]);
  568. }
  569. $cash_method = json_decode($saas_user->withdraw_method, true);
  570. if (is_array($cash_method)) {
  571. foreach ($cash_method as $key => $value) {
  572. if ($value['type'] == $type) {
  573. unset($cash_method[$key]);
  574. }
  575. }
  576. $saas_user->withdraw_method = json_encode(array_values($cash_method));
  577. } else {
  578. $saas_user->withdraw_method = '';
  579. }
  580. if ($saas_user->save()) {
  581. return $this->asJson([
  582. 'code' => 0,
  583. 'msg' => '操作成功',
  584. ]);
  585. }
  586. return $this->asJson([
  587. 'code' => 0,
  588. 'msg' => '操作失败',
  589. ]);
  590. }
  591. /**
  592. * 添加提现方式
  593. */
  594. public function actionAddCashMethod()
  595. {
  596. $type = post_params('type');
  597. if (empty($type)) {
  598. return $this->asJson([
  599. 'code' => 1,
  600. 'msg' => '参数错误',
  601. ]);
  602. }
  603. $name = post_params('name');
  604. $account = post_params('account');
  605. $bank = post_params('bank');
  606. $branch = post_params('branch');
  607. $card_no = post_params('card_no');
  608. $cash_img = post_params('cash_img');
  609. if (empty($name) || empty($account)) {
  610. return $this->asJson([
  611. 'code' => 1,
  612. 'msg' => '账号和姓名不能为空',
  613. ]);
  614. }
  615. if ($type == 'bank_card' && (empty($bank) || empty($card_no))) {
  616. return $this->asJson([
  617. 'code' => 1,
  618. 'msg' => '银行或支行不能为空',
  619. ]);
  620. }
  621. $data = [
  622. 'type' => $type,
  623. 'name' => $name,
  624. 'account' => $account,
  625. 'cash_img' => $cash_img,
  626. ];
  627. if ($type == 'bank_card') {
  628. $data['bank'] = $bank;
  629. $data['branch'] = $branch;
  630. $data['card_no'] = $card_no;
  631. }
  632. $saas_user = get_saas_user();
  633. if (empty($saas_user->withdraw_method)) {
  634. $saas_user->withdraw_method = json_encode(array_values([$data]));
  635. } else {
  636. $decode = json_decode($saas_user->withdraw_method, true);
  637. if (!$decode) {
  638. $saas_user->withdraw_method = json_encode(array_values([$data]));
  639. } else {
  640. foreach ($decode as $key => $value) {
  641. if ($value['type'] == $type) {
  642. unset($decode[$key]);
  643. break;
  644. }
  645. }
  646. $decode[] = $data;
  647. $saas_user->withdraw_method = json_encode(array_values($decode));
  648. }
  649. }
  650. if ($saas_user->save()) {
  651. return $this->asJson([
  652. 'code' => 0,
  653. 'msg' => '操作成功',
  654. ]);
  655. }
  656. return $this->asJson([
  657. 'code' => 1,
  658. 'msg' => '操作失败',
  659. ]);
  660. }
  661. //提现前置计算
  662. public function actionGetCashFront() {
  663. $post = post_params();
  664. $price = $post['price'];
  665. $cash_type = $post['cash_type'];
  666. $type = $post['type'];
  667. if (!in_array($cash_type, CashExt::CASH_TYPE_ARR)) {
  668. return $this->asJson([
  669. 'code' => 1,
  670. 'msg' => '提现类型错误',
  671. ]);
  672. }
  673. $store_id = get_store_id();
  674. if ($cash_type == CashExt::CASH_TYPE_INTEGRAL_APPRECIATION) {
  675. $price = CashExt::integral_appreciation_cash($price, $store_id)['cash_price'];
  676. }
  677. // 分销提现 股东提现 到余额的不扣除手续费
  678. return $this->asJson(CashExt::cashFront($cash_type, $store_id, $price, $type == 'money' ? 3 : 0));
  679. }
  680. /**
  681. * @return mixed|string
  682. * 申请提现
  683. */
  684. public function actionApply()
  685. {
  686. $form = new CashForm();
  687. $form->user_id = get_user_id();
  688. $form->store_id = get_store_id();
  689. $form->attributes = post_params();
  690. return $this->asJson($form->save());
  691. }
  692. /**
  693. * 提现明细列表
  694. */
  695. public function actionCashDetail()
  696. {
  697. $form = new CashListForm();
  698. $form->attributes = all_params();
  699. $form->store_id = get_store_id();
  700. $form->user_id = get_user_id();
  701. return $this->asJson($form->getList());
  702. }
  703. /**
  704. * @return mixed|string
  705. * 获取推广海报
  706. */
  707. public function actionGetQrcode()
  708. {
  709. $form = new ShareQrcodeForm();
  710. $form->store_id = get_store_id();
  711. $form->type = 4;
  712. $form->user = get_user();
  713. $form->user_id = get_user_id();
  714. //判断是否是分销商
  715. $share = Share::findOne(['user_id' => get_user_id(), 'status' => 1, 'is_delete' => 0]);
  716. if (empty($share)) {
  717. return $this->asJson([
  718. 'code' => 0,
  719. 'data' => '',
  720. 'status' => 1,
  721. 'msg' => '您还不是分销商'
  722. ]);
  723. }
  724. return $this->asJson($form->search());
  725. }
  726. /**
  727. * @return mixed|string
  728. * 商店分销设置信息
  729. */
  730. // TODO: ???
  731. public function actionShopShare()
  732. {
  733. // $list = Setting::find()->alias('s')
  734. // ->where(['s.store_id' => get_store_id()])
  735. // ->leftJoin('{{%qrcode}} q', 'q.store_id=s.store_id and q.is_delete=0')
  736. // ->select(['s.level', 'q.qrcode_bg'])
  737. // ->asArray()->one();
  738. // return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $list]);
  739. }
  740. /**
  741. * @return mixed|string
  742. * 绑定上下级关系
  743. */
  744. public function actionBindParent()
  745. {
  746. $form = new BindForm();
  747. $form->user_id = get_user_id();
  748. $form->store_id = get_store_id();
  749. $form->parent_id = get_params('parent_id');
  750. $form->condition = intval(get_params('condition'));
  751. $form->page_type = intval(all_params('page_type'));
  752. return $this->asJson($form->save());
  753. }
  754. /**
  755. * @return mixed|string
  756. * 获取团队详情
  757. */
  758. public function actionGetTeam()
  759. {
  760. $form = new TeamForm();
  761. $form->attributes = get_params();
  762. $form->user_id = get_user_id();
  763. $form->store_id = get_store_id();
  764. $form->scenario = "TEAM";
  765. return $this->asJson($form->getTeam());
  766. }
  767. /**
  768. * 获取分销订单
  769. * @return \yii\web\Response
  770. * @throws \yii\db\Exception
  771. */
  772. public function actionGetOrder()
  773. {
  774. $form = new TeamForm();
  775. $form->attributes = get_params();
  776. $form->user_id = get_user_id();
  777. $form->child_user_id = get_params('child_user_id');
  778. $form->store_id = get_store_id();
  779. $form->scenario = "ORDER";
  780. return $this->asJson($form->getOrder());
  781. }
  782. /**
  783. * @description: 充值订单
  784. * @param {*} $user
  785. * @return {*}
  786. */
  787. public function actionGetRechargeOrder()
  788. {
  789. $user = get_user();
  790. $form = new RcCommissionForm();
  791. $form->attributes = get_params();
  792. $form->store_id = get_store_id();
  793. $form->status = get_params('status');
  794. $form->page = get_params('page');
  795. $form->user = $user;
  796. $res = $form->search();
  797. return $this->asJson($res);
  798. }
  799. /**
  800. * 获取分销订单
  801. * @return \yii\web\Response
  802. * @throws \yii\db\Exception
  803. */
  804. public function actionGetOrder2()
  805. {
  806. $form = new TeamForm();
  807. $form->attributes = get_params();
  808. $form->user_id = get_user_id();
  809. $form->store_id = get_store_id();
  810. $form->scenario = "ORDER";
  811. return $this->asJson($form->getOrder2());
  812. }
  813. /**
  814. * 修改分销订单门店
  815. */
  816. public function actionSetOrderMdId()
  817. {
  818. $order_id = get_params('order_id');
  819. $md_id = get_params('md_id');
  820. $order = Order::findOne($order_id);
  821. if (!$order) {
  822. return $this->asJson([
  823. 'code' => 1,
  824. 'msg' => '订单不存在'
  825. ]);
  826. }
  827. $md = Md::findOne($md_id);
  828. if (!$md) {
  829. return $this->asJson([
  830. 'code' => 1,
  831. 'msg' => '门店不存在'
  832. ]);
  833. }
  834. $order->md_id = $md_id;
  835. $order->save();
  836. return $this->asJson([
  837. 'code' => 0,
  838. 'msg' => '修改成功'
  839. ]);
  840. }
  841. public function actionGetShareOrder() {
  842. $store_id = get_store_id();
  843. $user_id = get_user_id();
  844. $page = get_params('page', 1);
  845. $limit = get_params('limit', 20);
  846. $query = UserShareMoney::find()->alias('usm')->where(['usm.store_id' => $store_id, 'usm.user_id' => $user_id,
  847. 'usm.type' => 0, 'usm.source' => 5])->leftJoin(['o' => Order::tableName()], 'o.id = usm.order_id')
  848. ->leftJoin(['u' => User::tableName()], 'u.id=usm.user_id')
  849. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
  850. $count = $query->count();
  851. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  852. $list = $query->select('o.*, su.avatar as avatar_url, su.name as nickname')->orderBy('usm.created_at desc')
  853. ->limit($pagination->limit)
  854. ->offset($pagination->offset)->asArray()->all();
  855. $new_list = [];
  856. foreach ($list as $index => $value) {
  857. $new_list[$index]['share_send_type'] = $value['share_send_type'];
  858. $new_list[$index]['order_type'] = $value['order_type'];
  859. $new_list[$index]['order_no'] = $value['order_no'];
  860. $new_list[$index]['nickname'] = $value['nickname'];
  861. $new_list[$index]['avatar_url'] = $value['avatar_url'];
  862. $new_list[$index]['is_price'] = $value['is_price'];
  863. $new_list[$index]['status'] = "待付款";
  864. if ($value['is_pay'] == 0) {
  865. $new_list[$index]['status'] = "待付款";
  866. } elseif ($value['is_pay'] == 1 && $value['is_price'] == 0) {
  867. $new_list[$index]['status'] = "已付款";
  868. } elseif ($value['is_price'] == 1) {
  869. $new_list[$index]['status'] = "已完成";
  870. }
  871. $new_list[$index]['share_status'] = '分享返现';
  872. $new_list[$index]['share_money'] = $value['share_order_profit'];
  873. // 订单商品详情
  874. $form = new TeamForm();
  875. $new_list[$index]['orderDetail'] = $form->getOrderDetail($value['id']);
  876. $refund = OrderRefund::findOne(['order_id' => $value['id'], 'is_delete' => 0,
  877. 'store_id' => $this->store_id, 'type' => 1]);
  878. if ($refund) {
  879. if ($refund['status'] == 1) {
  880. $new_list[$index]['status'] = "已退款";
  881. } elseif ($refund['status'] == 0) {
  882. $new_list[$index]['status'] = '售后申请中';
  883. }
  884. }
  885. }
  886. return $this->asJson([
  887. 'code' => 0,
  888. 'msg' => 'success',
  889. 'data' => [
  890. 'row_count' => $count,
  891. 'page_count' => $pagination->pageCount,
  892. 'list' => $new_list,
  893. ]
  894. ]);
  895. }
  896. /**
  897. * 获取分销配置
  898. * @return \yii\web\Response
  899. */
  900. public function actionIndex()
  901. {
  902. $form = new ShareForm();
  903. $form->store_id = get_store_id();
  904. return $this->asJson($form->getShareSetting());
  905. }
  906. //佣金明细
  907. public function actionGetUserShareMoney()
  908. {
  909. $store_id = get_store_id();
  910. $user_id = get_user_id();
  911. $query = UserShareMoney::find()
  912. ->where(['store_id' => $store_id, 'user_id' => $user_id])
  913. // 如果记录money为0,不显示
  914. ->andWhere(['>', 'money', 0])
  915. // ->alias('usm')
  916. // ->where(['usm.store_id' => $store_id, 'usm.user_id' => $user_id, 'usm.type' => 0])
  917. // ->leftJoin(['o' => Order::tableName()], 'o.id = usm.order_id and usm.order_type in (0, 1, 2, 3)')
  918. // ->leftJoin(['lo' => LevelOrder::tableName()], 'lo.id = usm.order_id and usm.order_type = 4')
  919. // ->leftJoin(['ro' => ReOrder::tableName()], 'ro.id = usm.order_id and usm.order_type = 5')
  920. // ->select('usm.*, o.order_no, lo.order_no l_order_no, ro.order_no r_order_no')
  921. ->orderBy('id DESC');
  922. $list = pagination_make($query);
  923. foreach ($list['list'] as &$item) {
  924. //提需求说是要显示佣金来源的详细信息
  925. $desc = "";
  926. if (in_array($item['order_type'], [0, 1, 2, 3])) {
  927. $order = Order::findOne($item['order_id']);
  928. //提需求说是要显示xx用户购买了xx等多件商品 产生的以及/二级佣金
  929. $orderDetail = OrderDetail::find()->where(['order_id' => $item['order_id'], 'is_delete' => 0])
  930. ->select('goods_name, num')->asArray()->all();
  931. $desc .= "购买";
  932. $goods_str = '';
  933. foreach ($orderDetail as $order_goods_item) {
  934. $goods_str .= $order_goods_item['goods_name'];
  935. }
  936. $goods_str = mb_substr($goods_str, 0, 15, 'utf-8');
  937. // 去除非utf8字符
  938. if (function_exists('iconv')) {
  939. // 使用iconv函数去除非UTF-8字符
  940. $goods_str = iconv('UTF-8', 'UTF-8//IGNORE', $goods_str);
  941. } else {
  942. // 如果iconv不可用,则使用正则表达式尝试去除非UTF-8字符
  943. $goods_str = preg_replace('/[^\x{0000}-\x{FFFF}]/u', '', $goods_str);
  944. }
  945. $desc .= $goods_str . "……等商品产生的" . UserShareMoney::getSourceName($item['source'], $store_id) . "佣金";
  946. } elseif (intval($item['order_type']) === 4) {
  947. $order = LevelOrder::findOne($item['order_id']);
  948. $level_name = "";
  949. if ($order) {
  950. $level = Level::findOne(['store_id' => $store_id, 'level' => $order->after_level, 'is_delete' => 0]);
  951. $level_name = $level->name ?? '';
  952. }
  953. $desc .= "购买{$level_name}等级";
  954. } elseif (intval($item['order_type']) === 5) {
  955. $order = ReOrder::findOne($item['order_id']);
  956. }
  957. $user = [
  958. 'name' => ''
  959. ];
  960. if (!empty($order)) {
  961. $user = User::find()->alias('u')->where(['u.id' => $order->user_id])
  962. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')->select('su.name')
  963. ->asArray()->one();
  964. }
  965. $desc = '商城会员: ' . $user['name'] . $desc;
  966. $item['order_no'] = $order->order_no ?? '';
  967. $item['l_order_no'] = $order->order_no ?? '';
  968. $item['r_order_no'] = $order->order_no ?? '';
  969. $item['source_name'] = UserShareMoney::getSourceName($item['source'], $store_id);
  970. $item['source_desc'] = "";
  971. // if (intval($item['order_type']) === 4 && !empty($order)) {
  972. //
  973. // }
  974. $item['source_desc'] = $desc;
  975. if (!$item['order_no']) {
  976. $item['order_no'] = $item['l_order_no'];
  977. }
  978. if(!$item['l_order_no'] && !$item['order_no']){
  979. $item['order_no'] = $item['r_order_no'];
  980. }
  981. $item['type'] = intval($item['type']);
  982. }
  983. $list['data'] = $list['list'];
  984. unset($list['list']);
  985. return $this->asJson([
  986. 'code' => 0,
  987. 'msg' => 'success',
  988. 'data' => $list,
  989. ]);
  990. }
  991. }