SaasController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\controllers;
  8. use app\models\Admin;
  9. use app\models\Option;
  10. use app\models\SaasDistribution;
  11. use app\models\SaasHistory;
  12. use app\models\SaaSLeaguePriceLog;
  13. use app\models\SaasProfitCash;
  14. use app\models\SaasUser;
  15. use app\models\Store;
  16. use app\models\User;
  17. use app\models\Favorite;
  18. use app\modules\alliance\models\OrderMemberForm;
  19. use app\modules\alliance\models\OrderListForm;
  20. use app\modules\alliance\models\AddressSaveForm;
  21. use app\modules\alliance\models\BusinessMemberOrderPayDataForm;
  22. use app\modules\alliance\models\AddressSetDefaultForm;
  23. use app\modules\alliance\models\FavoriteAddForm;
  24. use app\modules\alliance\models\FavoriteListForm;
  25. //use app\modules\alliance\models\AddressSetDefaultForm;
  26. use app\models\Address;
  27. use app\models\SaasCoupon;
  28. use app\models\BrowseLog;
  29. use app\models\SharingReceiver;
  30. use app\utils\Ocr\OcrApi;
  31. use app\utils\OrderNo;
  32. use yii\data\Pagination;
  33. use yii\helpers\Json;
  34. use app\models\Purchase;
  35. use app\models\StoreCloud;
  36. /**
  37. * 用户
  38. */
  39. class SaasController extends BaseController
  40. {
  41. private $alliance_store_id = -1;
  42. public function behaviors()
  43. {
  44. return parent::behaviors();
  45. }
  46. private function getDefaultData()
  47. {
  48. $data = [
  49. 'orders' => [
  50. 'status_0' => [
  51. 'text' => '待付款',
  52. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-0.png',
  53. ],
  54. 'status_1' => [
  55. 'text' => '待发货',
  56. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-1.png',
  57. ],
  58. 'status_2' => [
  59. 'text' => '待收货',
  60. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-2.png',
  61. ],
  62. 'status_3' => [
  63. 'text' => '已完成',
  64. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-3.png',
  65. ],
  66. 'status_4' => [
  67. 'text' => '售后',
  68. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-4.png',
  69. ],
  70. ]
  71. ];
  72. return $data;
  73. }
  74. public function actionGetUserPrice()
  75. {
  76. $saasUser = get_saas_user();
  77. if (!$saasUser) {
  78. return $this->asJson([
  79. 'code' => 1,
  80. 'msg' => "参数解析错误"
  81. ]);
  82. }
  83. $data = [
  84. 'share_profit' => $saasUser->share_profit,
  85. 'name' => $saasUser->name,
  86. 'avatar' => $saasUser->avatar
  87. ];
  88. return $this->asJson($data);
  89. }
  90. public function actionGetCategoryInfo()
  91. {
  92. $list = \app\models\SaasCategory::findAll(['is_delete' => 0]);
  93. return $this->asJson([
  94. 'code' => 0,
  95. 'data' => $list,
  96. ]);
  97. }
  98. /**
  99. * 用户中心
  100. * @return \yii\web\Response
  101. */
  102. public function actionIndex()
  103. {
  104. $data = $this->getDefaultData();
  105. $data = [
  106. 'code' => 0,
  107. 'data' => $data,
  108. 'msg' => 'success'
  109. ];
  110. $saasUser = get_saas_user();
  111. $is_admin = 0;
  112. $is_store_admin = 0;
  113. if ($saasUser) {
  114. $is_admin = !empty($saasUser->id) ? Admin::findOne(['saas_user_id' => $saasUser->id, 'is_delete' => 0, 'type'=>"admin"]) : "";
  115. // 根据admin表中手机号判断当前是否为客户端管理员,后期需添加admin表中的手机号编辑
  116. $store_admin = Admin::find()->where(['mobile' => $saasUser->mobile, 'is_delete' => 0, 'type' => 'store'])->orderBy('id DESC')->one();
  117. if($store_admin){
  118. $is_store_admin = Store::findOne(['id' => $store_admin->type_id, 'is_delete' => 0]);
  119. }else{
  120. $is_store_admin = '';
  121. }
  122. }
  123. $storeCloud = StoreCloud::find()
  124. ->where(['is_delete' => 0, 'is_enable' => 1, 'saas_user_id' => $saasUser['id']])
  125. ->one();
  126. $is_can_distribution = $storeCloud && $storeCloud->store_id > 0 ? 1 : 0;// 是否有商城(是否可以铺货)
  127. $is_can_distribution = $is_can_distribution && $storeCloud['can_distribution'] ? 1 : 0;// 否具备 一键铺货选品的权限
  128. //店铺积分
  129. $store_integral = User::find()->alias('u')->leftJoin(['s' => Store::tableName()], 'u.store_id = s.id')
  130. ->where(['u.is_delete' => 0, 's.is_delete' => 0, 'binding' => $saasUser->mobile])->andWhere(['IS NOT', 's.id', NULL])->sum('u.integral') ?: 0;
  131. $user_data_info = [
  132. 'access_token' => $saasUser['access_token'],
  133. 'avatar_url' => $saasUser['avatar'],
  134. 'binding' => $saasUser['mobile'],
  135. 'id' => $saasUser['id'],
  136. 'nickname' => $saasUser['name'],
  137. 'saas_money' => $saasUser['share_profit'],
  138. 'is_salesman' => $saasUser['is_salesman'],
  139. 'is_admin' => empty($is_admin) ? 0 : 1,
  140. 'is_store_admin' => empty($is_store_admin) ? 0 : 1,
  141. 'gender' => $saasUser['gender'],
  142. 'is_purchase' => $storeCloud ? 1 : 0, // 是否为采购员
  143. 'is_can_distribution' => $is_can_distribution, // 是否有商城(是否可以铺货)
  144. 'can_distribution' => $storeCloud['can_distribution'] ?? 0, // 否具备 一键铺货选品的权限
  145. 'league_price' => $saasUser->league_price,
  146. 'integral' => $saasUser->integral,
  147. 'store_integral' => $store_integral
  148. ];
  149. $data['data']['user_info'] = $user_data_info;
  150. /**
  151. * 获取用户优惠券数量
  152. */
  153. $coupon_num = SaasCoupon::find()->where([
  154. 'saas_id' => get_saas_user_id(),
  155. 'is_delete' => 0,
  156. 'is_use' => 0,
  157. 'is_expire' => 0,
  158. ])->count();
  159. /**
  160. * 获取浏览记录数量(包含商品和店铺的总数)
  161. */
  162. $browse_log_num = BrowseLog::find()->where([
  163. 'saas_id' => get_saas_user_id(),
  164. //'store_id' => get_store_id(),
  165. 'is_delete' => 0,
  166. ])->count();
  167. /**
  168. * 获取用户收藏商品数量
  169. */
  170. $favorite_goods_num = Favorite::find()->where([
  171. 'saas_id' => get_saas_user_id(),
  172. 'is_delete' => 0
  173. ])->count();
  174. $order_count = OrderListForm::getCountData(get_saas_user_id());
  175. $distribution = SaasDistribution::findOne(['saas_id' => get_saas_user_id()]);
  176. $is_distribution = false;
  177. if (is_wechat_platform()) {
  178. if (!empty($distribution->platform_open_id)) {
  179. $is_distribution = true;
  180. }
  181. }
  182. if (is_alipay_platform()) {
  183. if (empty($distribution->ali_name)) {
  184. $is_distribution = true;
  185. }
  186. }
  187. // start 获取核销码
  188. // TODO 这里要做支付宝小程序兼容
  189. $code_url = '';
  190. if (isset($data['data']['user_info'])) {
  191. $data['data']['user_info']['is_can_wechat'] = 0;
  192. if (strpos($data['data']['user_info']['nickname'], '****') !== false) {
  193. $data['data']['user_info']['is_can_wechat'] = 1;
  194. }
  195. }
  196. $arr = [
  197. 'code' => 0,
  198. 'msg' => 'success',
  199. 'data' => [
  200. 'order_count' => $order_count,
  201. 'show_customer_service' => 1,
  202. 'user_info' => isset($data['data']['user_info']) ? $data['data']['user_info'] : null,
  203. 'orders' => $data['data']['orders'],
  204. 'coupon_num' => $coupon_num,
  205. 'favorite_goods_num' => $favorite_goods_num,
  206. 'browse_log_num' => $browse_log_num,
  207. 'code_url' => $code_url,
  208. 'is_distribution' => $is_distribution
  209. ],
  210. ];
  211. return $this->asJson($arr);
  212. }
  213. /**
  214. * 会员支付
  215. */
  216. public function actionSubmitMember()
  217. {
  218. $form = new OrderMemberForm();
  219. $form->saas_id = get_saas_user_id();
  220. $form->attributes = post_params();
  221. return $this->asJson($form->save());
  222. }
  223. /**
  224. * 支付
  225. * @return \yii\web\Response
  226. */
  227. public function actionMemberPayData()
  228. {
  229. $form = new BusinessMemberOrderPayDataForm();
  230. $form->attributes = post_params();
  231. $form->store_id = get_store_id();
  232. return $this->asJson($form->search());
  233. }
  234. /**
  235. * 假支付
  236. * @return \yii\web\Response
  237. */
  238. public function actionFpay(){
  239. $pay_price = get_params('price',0);
  240. $code = get_params('code');
  241. // $type = get_params('type');
  242. $goods_names = '测试支付';
  243. $form = new BusinessMemberOrderPayDataForm();
  244. return $this->asJson($form->falsePay($goods_names, $pay_price, $code));
  245. }
  246. /**
  247. * 设为默认收货地址
  248. * @return \yii\web\Response
  249. */
  250. public function actionAddressSetDefault()
  251. {
  252. $form = new AddressSetDefaultForm();
  253. $form->attributes = get_params();
  254. $form->store_id = $this->alliance_store_id;
  255. $form->user_id = get_saas_user_id();
  256. return $this->asJson($form->save());
  257. }
  258. /**
  259. * 收货地址详情
  260. * @return \Yii\web\Response
  261. */
  262. public function actionAddressDetail()
  263. {
  264. $form = new AddressSetDefaultForm();
  265. $form->address_id = get_params('id');
  266. $form->store_id = $this->alliance_store_id;
  267. $form->user_id = get_saas_user_id();
  268. return $this->asJson($form->info());
  269. }
  270. /**
  271. * 删除收货地址
  272. * @return \yii\web\Response
  273. */
  274. public function actionAddressDelete()
  275. {
  276. $form = new AddressSetDefaultForm();
  277. $form->attributes = get_params();
  278. $form->store_id = $this->alliance_store_id;
  279. $form->user_id = get_saas_user_id();
  280. return $this->asJson($form->delete());
  281. }
  282. /**
  283. * 保存收货地址
  284. * @return \yii\web\Response
  285. */
  286. public function actionAddressSave()
  287. {
  288. $form = new AddressSaveForm();
  289. $form->attributes = post_params();
  290. $form->store_id = $this->alliance_store_id;
  291. $form->user_id = get_saas_user_id();
  292. return $this->asJson($form->save());
  293. }
  294. /**
  295. * 获取收货地址
  296. * @return \yii\web\Response
  297. */
  298. public function actionAddressList()
  299. {
  300. $query = Address::find()->where([
  301. 'is_delete' => 0,
  302. 'user_id' => get_saas_user_id(),
  303. ]);
  304. $list = $query->orderBy('is_default DESC,addtime DESC')->select('id,name,mobile,province_id,province,city_id,city,district_id,district,detail,is_default')->asArray()->all();
  305. foreach ($list as $i => $item) {
  306. $list[$i]['address'] = $item['province'] . $item['city'] . $item['district'] . $item['detail'];
  307. }
  308. return $this->asJson([
  309. 'code' => 0,
  310. 'msg' => 'success',
  311. 'data' => [
  312. 'list' => $list,
  313. ],
  314. ]);
  315. }
  316. /**
  317. * 获取信息
  318. * @return \yii\web\Response
  319. */
  320. public function actionOcrInfo() {
  321. $type = post_params('type');
  322. if (empty($type) || !in_array($type, OcrApi::$validType)) {
  323. return $this->asJson([
  324. 'code' => 1,
  325. 'msg' => '类型参数错误'
  326. ]);
  327. }
  328. $side = post_params('side');
  329. if (empty($side) && $type == OcrApi::TYPE_ID_CARD) {
  330. return $this->asJson([
  331. 'code' => 1,
  332. 'msg' => '身份证参数有误'
  333. ]);
  334. }
  335. $url = post_params('url');
  336. if (empty($url)) {
  337. return $this->asJson([
  338. 'code' => 1,
  339. 'msg' => '图片地址为空'
  340. ]);
  341. }
  342. try {
  343. $ocr = new OcrApi(true);
  344. switch ($type) {
  345. case OcrApi::TYPE_LICENSE:
  346. $res = $ocr->getBusinessLicense($url);
  347. break;
  348. case OcrApi::TYPE_ID_CARD:
  349. $res = $ocr->getIDCard($url, $side);
  350. break;
  351. case OcrApi::TYPE_BANK:
  352. $res = $ocr->getBankCard($url);
  353. break;
  354. case OcrApi::TYPE_TEXT:
  355. $res = $ocr->getTextRecognition($url, 1);
  356. break;
  357. }
  358. if ($res['code'] == 0 && !empty($res['data'])) {
  359. return $this->asJson($res);
  360. }
  361. return $this->asJson([
  362. 'code' => 1,
  363. 'msg' => '获取信息失败,请手动输入'
  364. ]);
  365. } catch (\Exception $e) {
  366. return $this->asJson([
  367. 'code' => 1,
  368. 'msg' => $e->getMessage()
  369. ]);
  370. }
  371. }
  372. public function actionOtherInfo() {
  373. $cloud_supplier_banner = Option::get('cloud_supplier_banner', 0, 'saas', '')['value'];
  374. $admin_copyright = Option::get('store_apply_agreement', 0, 'saas', '')['value'];
  375. $cloud_supplier_apply_agreement = Option::get('cloud_supplier_apply_agreement', 0, 'saas', '')['value'];
  376. $supplier_custom_form = Option::get('supplier_custom_form', 0, 'saas', json_encode([]))['value'];
  377. return $this->asJson([
  378. 'code' => 0,
  379. 'data' => [
  380. 'cloud_supplier_banner' => $cloud_supplier_banner ? Json::decode($cloud_supplier_banner) : [],
  381. 'store_apply_agreement' => $admin_copyright,
  382. 'cloud_supplier_apply_agreement' => $cloud_supplier_apply_agreement,
  383. 'supplier_custom_form' => json_decode($supplier_custom_form),
  384. ]
  385. ]);
  386. }
  387. /**
  388. * 联盟佣金提现提交
  389. */
  390. public function actionCashCommit() {
  391. $amount = post_params('amount');
  392. if ($amount < 0.01) {
  393. return $this->asJson([
  394. 'code' => 1,
  395. 'msg' => '提现最小金额不能小于0.01元'
  396. ]);
  397. }
  398. $user = !empty(get_user()) ? get_user() : User::find()->where(['binding'=>get_saas_user()->mobile])->one();
  399. $saas_user = SaasUser::findOne(['mobile' => $user->binding]);
  400. if ($saas_user->share_profit < $amount) {
  401. return $this->asJson([
  402. 'code' => 1,
  403. 'msg' => '当前提现金额大于可提现联盟佣金'
  404. ]);
  405. }
  406. if (!$saas_user->platform_open_id) {
  407. return $this->asJson([
  408. 'code' => 1,
  409. 'msg' => '请先绑定平台小程序openid'
  410. ]);
  411. }
  412. $t = \Yii::$app->db->beginTransaction();
  413. $cash = new SaasProfitCash();
  414. $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_SAAS_PROFIT_CASH);
  415. $cash->user_id = get_saas_user_id();
  416. $cash->mobile = $user->binding;
  417. $cash->amount = $amount;
  418. $cash->status = SaasProfitCash::CASH_STATUS_WAIT;
  419. $cash->created_at = time();
  420. if (!$cash->save()) {
  421. return $this->asJson([
  422. 'code' => 1,
  423. 'msg' => $cash->errors[0]
  424. ]);
  425. }
  426. $cash->before_price = $saas_user->share_profit;
  427. $cash->after_price = ($saas_user->share_profit - $amount);
  428. $saas_user->share_profit = $saas_user->share_profit - $amount;
  429. $saas_user->save();
  430. $t->commit();
  431. return $this->asJson([
  432. 'code' => 0,
  433. 'msg' => '提交成功,请等待审核'
  434. ]);
  435. }
  436. /**
  437. * 联盟佣金提现列表
  438. */
  439. public function actionCashList() {
  440. $page = get_params('page', 1);
  441. $limit = get_params('limit', 10);
  442. $status = get_params('status', -1);
  443. $user = get_user();
  444. $query = SaasProfitCash::find()->where(['mobile' => !empty($user->binding) ? $user->binding : get_saas_user()->mobile]);
  445. if ($status > -1) {
  446. if ($status <= 2) {
  447. $query->andWhere(['status' => $status]);
  448. } else {
  449. $query->andWhere(['is_pay' => 1]);
  450. }
  451. }
  452. $count = $query->count();
  453. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  454. $list = $query->select('*')->limit($pagination->limit)
  455. ->offset($pagination->offset)
  456. ->asArray()->orderBy(['created_at' => SORT_DESC])->all();
  457. foreach ($list as &$value) {
  458. $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
  459. $value['amount'] = sprintf("%.2f", ($value['amount'] - $value['service_money']));
  460. $value['status_text'] = $value['status'] == 0 ? '待审核' : ($value['status'] == 1 ? '已通过' : '已拒绝');
  461. if ($value['status'] == 1 && $value['is_pay'] == 1) {
  462. $value['status'] = 4;
  463. $value['status_text'] = '已打款';
  464. }
  465. $value['updated_at'] = $value['updated_at'] ? date('Y-m-d H:i:s', $value['updated_at']) : null;
  466. $value['status'] = (string)$value['status'];
  467. }
  468. return $this->asJson([
  469. 'code' => 0,
  470. 'msg' => 'success',
  471. 'data' => [
  472. 'row_count' => $count,
  473. 'page_count' => $pagination->pageCount,
  474. 'list' => $list,
  475. ]
  476. ]);
  477. }
  478. public function actionAddHistory()
  479. {
  480. $saas_user_id = get_saas_user_id();
  481. if ($saas_user_id > 0) {
  482. $store_id = get_store_id();
  483. $history = SaasHistory::find()->where(['user_id' => $saas_user_id, 'store_id' => $store_id])->one();
  484. if ($history) {
  485. $history->updated_at = time();
  486. $history->save();
  487. } else {
  488. $history = new SaasHistory();
  489. $history->user_id = $saas_user_id;
  490. $history->store_id = $store_id;
  491. $history->updated_at = time();
  492. $history->save();
  493. }
  494. }
  495. return $this->asJson([
  496. 'code' => 0,
  497. 'msg' => '添加成功',
  498. ]);
  499. }
  500. public function actionGetHistory()
  501. {
  502. $page = get_params('page', 1);
  503. $limit = 10;
  504. $query = SaasHistory::find()->alias('sh')
  505. ->leftJoin(['s' => Store::tableName()], 'sh.store_id=s.id')
  506. ->select(['s.id', 's.name', 's.logo']);
  507. $count = $query->count();
  508. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  509. $query->limit($limit)->offset($pagination->offset);
  510. $list = $query->orderBy(['sh.updated_at' => SORT_DESC])->asArray()->all();
  511. return $this->asJson([
  512. 'code' => 0,
  513. 'msg' => 'success',
  514. 'data' => $list,
  515. ]);
  516. }
  517. /**
  518. * 喜欢的商品或店铺列表
  519. */
  520. public function actionCheckFavorite()
  521. {
  522. $is_favorite = Favorite::find()->where(['store_id'=>get_store_id(),'saas_id'=>get_saas_user_id(),'is_delete'=>0])->one();
  523. $storeInfo = Store::find()->where(['id'=>get_store_id(),'is_delete'=>0])->one();
  524. $store_name = '';
  525. if(isset($storeInfo->name)){
  526. $store_name = $storeInfo->name;
  527. }
  528. $status = (isset($is_favorite->id) && $is_favorite->id > 0) ? 1 : 0;
  529. return $this->asJson([
  530. 'code' => 0,
  531. 'msg' => 'success',
  532. 'data'=>[
  533. 'status' => $status,
  534. 'store_name' => $store_name
  535. ]
  536. ]);
  537. }
  538. /**
  539. * 添加商品或店铺到我的喜欢
  540. */
  541. public function actionFavoriteAdd()
  542. {
  543. $form = new FavoriteAddForm();
  544. $form->attributes = post_params();
  545. $form->store_id = get_store_id();
  546. $form->saas_id = get_saas_user_id();
  547. $form->user_id = 0;
  548. return $this->asJson($form->save());
  549. }
  550. /**
  551. * 喜欢的商品或店铺列表
  552. */
  553. public function actionFavoriteList()
  554. {
  555. $form = new FavoriteListForm();
  556. $form->attributes = get_params();
  557. $form->saas_id = get_saas_user_id();
  558. $form->user_id = 0;
  559. //$form->store_id = get_store_id();
  560. return $this->asJson($form->search());
  561. }
  562. /**
  563. * 取消喜欢的商品或店铺列表
  564. */
  565. public function actionRemoveFavorite()
  566. {
  567. $id = get_store_id();
  568. if (empty($id)) {
  569. return $this->asJson([
  570. 'code' => 1,
  571. 'msg' => '参数错误'
  572. ]);
  573. }
  574. // if (!is_array($id)) {
  575. // $res = Favorite::updateAll(['is_delete' => 1], ['goods_id' => $id, 'user_id' => get_user_id(), 'type' => post_params('type', 0)]);
  576. // } else {
  577. // $res = Favorite::updateAll(['is_delete' => 1], ['and', ['in', 'goods_id', $id], ['user_id' => get_user_id(), 'type' => post_params('type', 0)]]);
  578. // }
  579. $res = Favorite::updateAll(['is_delete' => 1], ['store_id' => $id, 'saas_id' => get_saas_user_id(), 'type' => post_params('type', 0)]);
  580. if ($res) {
  581. return $this->asJson([
  582. 'code' => 0,
  583. 'msg' => '删除成功',
  584. ]);
  585. } else {
  586. return $this->asJson([
  587. 'code' => 1,
  588. 'msg' => 'fail',
  589. 'err' => $res
  590. ]);
  591. }
  592. }
  593. public function actionSearchKeyword()
  594. {
  595. $keyword = Option::get('search_keyword', 0, 'saas', json_encode([]));
  596. return $this->asJson([
  597. 'code' => 0,
  598. 'msg' => 'success',
  599. 'data' => json_decode($keyword['value']),
  600. ]);
  601. }
  602. //获取返利数据
  603. public function actionRebaseInfo(){
  604. $saas_id = get_saas_user_id();
  605. //echo $saas_id;exit;
  606. $receiverInfo = SharingReceiver::find()->where(['saas_id'=>$saas_id,'is_delete'=>0])->andWhere([
  607. 'or',['and',['is_pay'=>0]],['and',['is_pay'=>1]]
  608. ])->asArray()->all();
  609. $total = $finish = $nofinish = 0;
  610. foreach($receiverInfo as $val){
  611. $total += $val['amount'];
  612. if($val['is_pay'] == 0){
  613. $nofinish += $val['amount'];
  614. }
  615. if($val['is_pay'] == 1){
  616. $finish += $val['amount'];
  617. }
  618. }
  619. $data['total'] = $total;
  620. $data['nofinish'] = $nofinish;
  621. $data['finish'] = $finish;
  622. return $this->asJson([
  623. 'code' => 0,
  624. 'msg' => 'success',
  625. 'data' => $data
  626. ]);
  627. }
  628. //获取返利数据
  629. public function actionRebaseList(){
  630. $saas_id = get_saas_user_id();
  631. $status = get_params('status',-1);
  632. $page = get_params('page',1);
  633. $limit = 10;
  634. $query = SharingReceiver::find()->where(['saas_id'=>$saas_id,'is_delete'=>0]);
  635. if($status == -1){ //全部
  636. $query->andWhere([
  637. 'or',['and',['is_pay'=>0]],['and',['is_pay'=>1]]
  638. ]);
  639. }
  640. if($status == 0){ //未到账
  641. $query->andWhere(['is_pay'=>0]);
  642. }
  643. if($status == 1){ //已到账
  644. $query->andWhere(['is_pay'=>1]);
  645. }
  646. $count = $query->count();
  647. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  648. $query->limit($limit)->offset($pagination->offset);
  649. $list = $query->orderBy(['id' => SORT_DESC])->select('is_pay,created_at,amount,remark')->asArray()->all();
  650. return $this->asJson([
  651. 'code' => 0,
  652. 'msg' => 'success',
  653. 'data' => ['list'=>$list,'page'=>$page,'count'=>$count]
  654. ]);
  655. }
  656. /**
  657. * 获取联盟券记录
  658. */
  659. public function actionLeaguePriceLog() {
  660. $saas_user_id = get_saas_user()->id;
  661. $admin = Admin::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'type' => 'store']);
  662. $store = Store::findOne($admin->type_id);
  663. $send_or_take_type = get_params('send_or_take_type', -1);
  664. $type = get_params('type', -1);
  665. $query = SaaSLeaguePriceLog::find()->where(['store_id' => $store->id, 'is_delete' => 0, 'role' => SaaSLeaguePriceLog::ROLE_STORE])
  666. ->select('id, type, send_or_take_type, league_price, addtime, saas_user_id')->orderBy('addtime desc');
  667. if (isset($send_or_take_type) && $send_or_take_type >= 0) {
  668. $query->andWhere(['send_or_take_type' => $send_or_take_type]);
  669. }
  670. if (isset($type) && in_array($type, [0, 1])) {
  671. $query->andWhere(['type' => $type]);
  672. }
  673. $list = pagination_make($query);
  674. foreach ($list['list'] as &$item) {
  675. $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
  676. $item['type'] = (int)$item['type'];
  677. $item['send_or_take_type'] = (int)$item['send_or_take_type'];
  678. $item['name'] = '';
  679. $item['mobile'] = '';
  680. $item['avatar'] = '';
  681. if ($item['saas_user_id']) {
  682. $saasUser = SaasUser::findOne($item['saas_user_id']);
  683. if ($saasUser) {
  684. $item['name'] = $saasUser->name;
  685. $item['mobile'] = $saasUser->mobile;
  686. $item['avatar'] = $saasUser->avatar;
  687. }
  688. }
  689. }
  690. return $this->asJson([
  691. 'code' => 0,
  692. 'msg' => 'success',
  693. 'data' => [
  694. 'data' => $list['list'],
  695. 'pageNo' => $list['pageNo'],
  696. 'totalCount' => $list['totalCount']
  697. ]
  698. ]);
  699. }
  700. /**
  701. * 个人分账记录
  702. * @return \yii\web\Response
  703. */
  704. public function actionShareProfitRecord() {
  705. $page = get_params('page', 1);
  706. $limit = get_params('limit', 10);
  707. $saasUser = get_saas_user();
  708. $query = SharingReceiver::find()->where(['saas_id' => $saasUser->id]);
  709. $count = $query->count();
  710. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  711. $list = $query->select('*')->limit($pagination->limit)
  712. ->offset($pagination->offset)
  713. ->asArray()->orderBy(['created_at' => SORT_DESC])->all();
  714. foreach ($list as $key => $value) {
  715. $tmp = [];
  716. $tmp['order_no'] = $value['order_no'];
  717. $tmp['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
  718. $tmp['amount'] = $value['amount'];
  719. $tmp['remark'] = $value['remark'];
  720. $tmp['pay_status'] = $value['is_pay'] == 0 ? '待分账' : ($value['is_pay'] == 1 ? '已分账' : '分账失败-转佣金');
  721. $list[$key] = $tmp;
  722. }
  723. return $this->asJson([
  724. 'code' => 0,
  725. 'msg' => 'success',
  726. 'data' => [
  727. 'row_count' => $count,
  728. 'page_count' => $pagination->pageCount,
  729. 'list' => $list,
  730. ]
  731. ]);
  732. }
  733. }