SellerController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <?php
  2. namespace addons\Store\api\modules\v1\controllers;
  3. use addons\Store\common\enums\StoreEnum;
  4. use addons\Store\common\models\Store;
  5. use addons\Store\common\models\StoreBank;
  6. use addons\Store\common\models\StoreCommission;
  7. use addons\Store\common\models\StoreOrder;
  8. use addons\Store\common\models\StoreOrderCredit;
  9. use addons\Store\common\models\StoreRefundAddress;
  10. use addons\Store\common\models\StoreSettings;
  11. use addons\Store\common\models\StoreWithdrawLog;
  12. use api\controllers\OnAuthController;
  13. use common\enums\ExpressEnum;
  14. use common\enums\MarketingTypeEnum;
  15. use common\enums\OrderStatusEnum;
  16. use common\enums\PayTypeEnum;
  17. use common\enums\RefundStatusEnum;
  18. use common\enums\RefundTypeEnum;
  19. use common\enums\ShippingTypeEnum;
  20. use common\enums\StatusEnum;
  21. use common\models\goods\Goods;
  22. use common\models\order\Order;
  23. use common\models\order\OrderAction;
  24. use common\models\order\OrderExpress;
  25. use common\models\order\OrderRefund;
  26. use common\models\user\User;
  27. use common\enums\ApiStatusEnum;
  28. use common\globals\GlobalInvoke;
  29. use common\enums\WithdrawWayEnum;
  30. use common\models\common\PlatformSetting;
  31. use Yii;
  32. use yii\helpers\Json;
  33. /**
  34. * 门店卖家
  35. * Class SellerController
  36. * @package api\modules\order\controllers
  37. */
  38. class SellerController extends OnAuthController
  39. {
  40. public $modelClass = '';
  41. /**
  42. * 不用进行登录验证的方法
  43. *
  44. * 例如: ['index', 'update', 'create', 'view', 'delete']
  45. * 默认全部需要验证
  46. *
  47. * @var array
  48. */
  49. protected $authOptional = [];
  50. protected $store_id = 0;
  51. public function beforeAction($action)
  52. {
  53. parent::beforeAction($action);
  54. //检测门店身份
  55. $store = Store::find()
  56. ->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])
  57. ->one();
  58. if (empty($store)) {
  59. \Yii::$app->response->data = ['code' => 1, 'msg' => '您非门店身份'];
  60. \Yii::$app->response->send();
  61. return;
  62. }
  63. $this->store_id = $store->id;
  64. return $action;
  65. }
  66. /**
  67. * 门店订单列表
  68. * @return void
  69. */
  70. public function actionOrderList()
  71. {
  72. $param = \Yii::$app->request->get();
  73. $order_status_list = OrderStatusEnum::getMap();
  74. $payment_type_list = PayTypeEnum::getMap();
  75. $shipping_type_list = ShippingTypeEnum::getMap();
  76. $rules = [
  77. [['order_status'], 'in', 'range' => array_keys($order_status_list)],
  78. //[['payment_type'], 'in', 'range' => array_keys($payment_type_list)],
  79. //[['shipping_type'], 'in', 'range' => array_keys($shipping_type_list)],
  80. //[['start', 'end'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
  81. //[['order_no', 'mobile', 'order_id'], 'safe'],
  82. [['keyword','type'], 'string'],
  83. // ['mobile', 'match', 'pattern' => '/^1\d{10}$/', 'message' => '请输入正确的手机号码'],
  84. ];
  85. $res = Yii::$app->services->validate->validate($param, $rules);
  86. if (!$res) return $this->error(Yii::$app->services->validate->getErrorMessage());
  87. $where[] = ['mall_id' => $this->mall_id];
  88. $where[] = ['store_id' => $this->store_id];
  89. if (isset($param['order_status']) && $param['order_status'] != 999) {
  90. $where[] = ['order_status' => $param['order_status']];
  91. }
  92. if (isset($param['keyword']) && $param['keyword']) {
  93. switch (trim($param['type'])){
  94. case 'order_no':
  95. $where[] = ['order_no' => $param['keyword']];
  96. break;
  97. case 'mobile':
  98. $where[] = ['mobile' => $param['keyword']];
  99. break;
  100. case 'express':
  101. $express = OrderExpress::findOne(['express_no' => $param['keyword']]);
  102. if($express){
  103. $order = Order::findOne(['id' => $express->order_id,'mall_id' => $this->mall_id,'store_id' => $this->store_id]);
  104. $order && $where[] = ['order_no' => $order->order_no];
  105. }
  106. break;
  107. }
  108. }
  109. $where[] = ['=', 'supplier_type', 0];
  110. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  111. $with = ['base_user', 'detail'];
  112. $order = "id desc";
  113. $params = compact('where', 'with', 'order');
  114. $page_data = StoreOrder::listPage($params, false, true);
  115. if ($page_data === false) return $this->error(Goods::getStaticError());
  116. $compact_params = array_keys($page_data);
  117. extract($page_data);
  118. //订单数量:未付款,待发货,待收货
  119. $stat = StoreOrder::find()->select('count(id) as num ,order_status')->where(['mall_id' => $this->mall_id, 'store_id' => $this->store_id
  120. ])->groupBy('order_status')->asArray()->all();
  121. $stat = array_column($stat, 'num', 'order_status');
  122. //$stat_tab = [];
  123. $stat_tab[] = [
  124. 'order_status' => 999,
  125. 'num' => 0 ,
  126. 'order_status_text' => '全部'
  127. ];
  128. foreach ($order_status_list as $key => $value) {
  129. if (!in_array($key, [OrderStatusEnum::NOT_PAY, OrderStatusEnum::PAY, OrderStatusEnum::SHIPMENTS])) continue;
  130. $stat_tab[] = [
  131. 'order_status' => $key,
  132. 'num' => $stat[$key] ?? 0,
  133. 'order_status_text' => $value
  134. ];
  135. }
  136. return $this->success('操作成功', compact($compact_params, 'order_status_list', 'payment_type_list', 'shipping_type_list', 'export_list', 'marketing_type_map','stat_tab'));
  137. }
  138. /**
  139. * 售后订单列表
  140. * @return void
  141. */
  142. public function actionRefundList()
  143. {
  144. $param = Yii::$app->request->get();
  145. $refund_status_list = RefundStatusEnum::getMap();
  146. $refund_type_list = RefundTypeEnum::getMap();
  147. $rules = [
  148. [['keyword'], 'string'],
  149. [['keyword', 'refund_status'], 'safe'],
  150. ];
  151. $res = Yii::$app->services->validate->validate($param, $rules);
  152. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  153. $where = [['mall_id' => $this->mall_id]];
  154. $where[] = ['=', 'store_id', $this->store_id];
  155. $where[] = ['=', 'status', StatusEnum::ENABLED];
  156. if (isset($param['keyword']) && $param['keyword']) {
  157. //关键词 订单号:st202212161912558027820701
  158. if (substr($param['keyword'], 0, 2) == 'st') {
  159. //商城订单号搜索,查询对应订单id
  160. $search_order = OrderRefund::getOidByOrderNo($this->mall_id, $param['order_no']);
  161. if ($search_order) {
  162. $where[] = ['in', 'order_id', $search_order];
  163. }
  164. } else {
  165. preg_match('/^1\d{10}$/', $param['keyword'], $match);
  166. if ($match) {
  167. $where[] = OrderRefund::searchByKeyword($this->mall_id, 'mobile', $param['keyword']);
  168. } else {
  169. //快递单号查询不了
  170. }
  171. }
  172. }
  173. if (isset($param['refund_status']) && $param['refund_status'] != 999 ) {
  174. if($param['refund_status'] == RefundStatusEnum::HANDEL){
  175. //售后中
  176. $where[] = ['in', 'refund_status', [ RefundStatusEnum::HANDEL, RefundStatusEnum::RETURN_GOODS, RefundStatusEnum::EXCHANGE_GOODS]];
  177. }else{
  178. $where[] = ['=', 'refund_status', $param['refund_status']];
  179. }
  180. } else {
  181. $where[] = ['in', 'refund_status', [RefundStatusEnum::APPLY, RefundStatusEnum::HANDEL, RefundStatusEnum::FINISH, RefundStatusEnum::RETURN_GOODS, RefundStatusEnum::EXCHANGE_GOODS, RefundStatusEnum::REFUSE]];
  182. }
  183. $with = ['base_user', 'orderDetail', 'order'];
  184. $select = 'id,order_id,order_detail_id,reason,remark,refund_price,refund_status,user_id';
  185. $order = "id desc";
  186. $params = compact('where', 'with', 'order', 'select');
  187. $page_data = OrderRefund::listPage($params, false, true);
  188. if ($page_data === false) return $this->error(OrderRefund::getStaticError());
  189. $compact_params = array_keys($page_data);
  190. extract($page_data);
  191. foreach ($list as &$order) {
  192. foreach ($order['orderDetail'] as &$detail) {
  193. if (!empty($detail['attr_groups_format'])) {
  194. //规格
  195. $attr_groups_format = Json::decode($detail['attr_groups_format'], true);
  196. $attr_list = $attr_groups_format[$detail['sign_id']];
  197. $attr_group_name_list = array_column($attr_list, 'attr_group_name');
  198. $attr_name_list = array_column($attr_list, 'attr_name');
  199. $detail['attr_list'] = [];
  200. foreach ($attr_group_name_list as $index => $attr_group_name) {
  201. $detail['attr_list'][] = $attr_group_name . ':' . $attr_name_list[$index];
  202. }
  203. }
  204. }
  205. }
  206. //导航栏售后状态-数量
  207. $stat = OrderRefund::find()->select('count(id) as num ,refund_status')
  208. ->where(['mall_id' => $this->mall_id, 'store_id' => $this->store_id
  209. ])->groupBy('refund_status')->asArray()->all();
  210. $stat = array_column($stat, 'num', 'refund_status');
  211. //$stat_tab = [];
  212. $stat_tab[] = [
  213. 'refund_status' => 999,
  214. 'num' => 0 ,
  215. 'refund_status_text' => '全部'
  216. ];
  217. foreach ($refund_status_list as $key => $value) {
  218. if (!in_array($key, [RefundStatusEnum::APPLY, RefundStatusEnum::HANDEL, RefundStatusEnum::FINISH])) continue;
  219. $stat_tab[] = [
  220. 'refund_status' => $key,
  221. 'num' => $stat[$key] ?? 0,
  222. 'refund_status_text' => $value
  223. ];
  224. }
  225. return $this->success('操作成功', compact($compact_params, 'refund_status_list', 'refund_type_list', 'stat_tab'));
  226. }
  227. /**
  228. * 订单详情
  229. * @return void
  230. */
  231. public function actionOrderDetail()
  232. {
  233. $get = Yii::$app->request->get();
  234. $rules = [[['id'], 'required']];
  235. $res = Yii::$app->services->validate->validate($get, $rules);
  236. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  237. $order_status_list = OrderStatusEnum::getMap();
  238. $payment_type_list = PayTypeEnum::getMap();
  239. $shipping_type_list = ShippingTypeEnum::getMap();
  240. $where = [['mall_id' => $this->mall_id]];
  241. $where[] = ['=', 'id', $get['id']];
  242. $where[] = ['=', 'store_id', $this->store_id];
  243. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  244. $with = [
  245. 'base_user',
  246. 'detail'
  247. ];
  248. $params = compact('where', 'with');
  249. $order = StoreOrder::getOne($where, true, $with);
  250. if ($order === false) return $this->error(StoreOrder::getStaticError());
  251. $main_order = Order::getOne([['order_no'=>$order['order_no']]],true,['express','express_log']);
  252. $express_log = [];
  253. $order['order_type_text'] = '普通订单';
  254. //佣金分红
  255. $order['commission_total'] = 0;
  256. //服务费
  257. $order['service_fee'] = 0;
  258. //商家实收:
  259. $order['amount_received'] = 0;
  260. $store_commission = StoreCommission::findOne(['store_id'=>$this->store_id,'order_no' =>$order['order_no']]);
  261. if($store_commission){
  262. $order['service_fee'] = $store_commission->service_charge;
  263. $order['commission_total'] = $store_commission->addons_bonus;
  264. $order['amount_received'] = $store_commission->amount_received;
  265. }
  266. $order_setting = Yii::$app->services->setting->mall->get($this->mall_id, 'order');
  267. $order['payment_expire_time'] = $order_setting['payment_expire_time'] ?? 30;
  268. $order['auto_receiving_time'] = $order_setting['auto_receiving_time'] ?? 14;
  269. if (!empty($order['detail'])) {
  270. foreach ($order['detail'] as &$detail) {
  271. if (!empty($detail['attr_groups_format'])) {
  272. $attr_groups_format = json_decode($detail['attr_groups_format'], true);
  273. $attr_list = $attr_groups_format[$detail['sign_id']];
  274. $attr_group_name_list = array_column($attr_list, 'attr_group_name');
  275. $attr_name_list = array_column($attr_list, 'attr_name');
  276. $detail['attr_list'] = [];
  277. foreach ($attr_group_name_list as $index => $attr_group_name) {
  278. $detail['attr_list'][] = $attr_group_name . ':' . $attr_name_list[$index];
  279. }
  280. }
  281. }
  282. }
  283. $shipping_type_text = ShippingTypeEnum::getShippingType($order['shipping_type']);
  284. $step_arr = StoreEnum::setpArrMap($order['order_status'], $shipping_type_text);// 订单状态跟踪
  285. $order_action = OrderAction::getOrderAction([['order_id' => $main_order['id']]]);
  286. $stepArr[] = ['title' => '买家下单', 'created_at' => '0', 'is_step' => 0];
  287. $stepArr[] = ['title' => '买家付款', 'created_at' => '0', 'is_step' => 0,];
  288. $stepArr[] = ['title' => $shipping_type_text, 'created_at' => '0', 'is_step' => 0,];
  289. $stepArr[] = ['title' => '交易完成', 'created_at' => '0', 'is_step' => 0,];
  290. $store = Store::getOne([['id' => $order['store_id']]], true);
  291. return $this->success('操作成功', compact('order', 'stepArr', 'order_status_list', 'payment_type_list', 'shipping_type_list', 'step_arr', 'order_action', 'store'));
  292. }
  293. /**
  294. * 售后订单详情
  295. * @return mixed|void
  296. */
  297. public function actionRefundDetail()
  298. {
  299. $get = Yii::$app->request->get();
  300. $rules = [[['id'], 'required']];
  301. $res = Yii::$app->services->validate->validate($get, $rules);
  302. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  303. $order_status_list = OrderStatusEnum::getMap();
  304. $address_list = StoreRefundAddress::lists([
  305. 'where' => [
  306. ['store_id' => $this->store_id],
  307. ['status' => StatusEnum::ENABLED]
  308. ],
  309. 'select' => 'address,mobile,name, refund_name as consignee',
  310. ]);
  311. $where = [['mall_id' => $this->mall_id], ['store_id' => $this->store_id]];
  312. $where[] = ['=', 'id', $get['id']];
  313. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  314. $with = ['base_user', 'order', 'orderDetail', 'marketing', 'step'];
  315. $params = compact('where', 'with');
  316. $refund = OrderRefund::getOne($where, true, $with);
  317. if ($refund === false) return $this->error(OrderRefund::getStaticError());
  318. $main_order = Order::findOne(['id' => $refund['order_id']]);
  319. $store_order = StoreOrder::findOne(['order_no' => $main_order['order_no'] ?? 0]);
  320. $store_order_credit = StoreOrderCredit::find()->where(['type' => 1, 'order_id' => $store_order['id'] ?? 0])
  321. ->andWhere(['>', 'pay_time', 0])->one();
  322. $refund['orderDetail']['credit_money'] = 0;
  323. if (!empty($store_order_credit['extra'])) {
  324. $goods_id = $refund['orderDetail']['goods_id'];
  325. $extra = json_decode($store_order_credit['extra'], true);
  326. if (!empty($extra[$goods_id]['credit_money'])) {
  327. $refund['orderDetail']['goods_price'] = bcadd($refund['orderDetail']['goods_price'], $extra[$goods_id]['credit_money'], 2);
  328. $refund['orderDetail']['credit_money'] = $extra[$goods_id]['credit_money'];
  329. }
  330. }
  331. foreach ($refund['orderDetail'] as $key => $detail) {
  332. if (!empty($detail['attr_groups_format'])) {
  333. $attr_groups_format = Json::decode($detail['attr_groups_format'], true);
  334. $attr_list = $attr_groups_format[$detail['sign_id']];
  335. $attr_group_name_list = array_column($attr_list, 'attr_group_name');
  336. $attr_name_list = array_column($attr_list, 'attr_name');
  337. $detail['attr_list'] = [];
  338. }
  339. }
  340. // 返还优惠内容
  341. if (!empty($refund['marketing'])) {
  342. $discount = [];
  343. $marketing = $refund['marketing'];
  344. if (!empty($marketing['deduct_score'])) {
  345. $score_name = Yii::$app->services->setting->mall->get($this->mall_id, 'score.score_name');
  346. $discount[] = floatval($marketing['deduct_score']) . $score_name;
  347. }
  348. $refund['discount'] = implode('+', $discount);
  349. }
  350. $step_status = $refund['step'][0]['step_status'] ?? 0;
  351. $step_arr = RefundStatusEnum::stepNumArr(in_array($step_status, [RefundStatusEnum::STEP_NEGATIVE_1, RefundStatusEnum::STEP_NEGATIVE_2]) ? 1 : $refund['type']);// 进度条
  352. $step_text = RefundStatusEnum::getStepStatusText($step_status);
  353. $refund_type_text = RefundTypeEnum::getMap();
  354. $refund_status_text = RefundStatusEnum::getMap();
  355. $refund['type_text'] = $refund_type_text[$refund['type']] ?? '';
  356. $refund['refund_status_text'] = $refund_status_text[$refund['refund_status']] ?? '';
  357. //关闭时间
  358. $refund['finish_at'] = 0;
  359. if($refund['status'] == RefundStatusEnum::FINISH){
  360. //售后完成
  361. $refund['finish_at'] = $refund['updated_at'];
  362. }
  363. return $this->success('操作成功', compact('refund', 'order_status_list', 'step_arr', 'address_list', 'step_text'));
  364. }
  365. /**
  366. * 资产
  367. * @return mixed|void
  368. */
  369. public function actionFinance()
  370. {
  371. $store = Store::findOne(['id' => $this->store_id]);
  372. // $balance_cash_service_fee = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance.balance_cash_service_fee');
  373. $user = User::getOne([['id' => $store->user_id]], true, [], false, 'id,nickname,avatar_url,mobile');
  374. $finance = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'finance');
  375. $storeSetting = StoreSettings::findOne(['store_id' => $this->store_id]);
  376. $freeze_is_enable = 0;
  377. $finance_name = '资产';
  378. if(!empty($finance)){
  379. if(!empty($finance['freeze_is_enable'])){
  380. $freeze_is_enable = $finance['freeze_is_enable'];
  381. }
  382. if(!empty($finance['finance_name'])){
  383. $finance_name = $finance['finance_name'];
  384. }
  385. }
  386. //提现条件
  387. if(isset($finance['balance_cash_type'])){
  388. $cashType = json_decode($finance['balance_cash_type'],true);
  389. }else{
  390. //默认银行卡/余额提现
  391. $cashType = ['balance','bank'];
  392. }
  393. $balance_cash_service_fee = 0;
  394. $balance_cash_service_fee_limit = 0;
  395. $balance_cash_service_fee_month = 0;
  396. if (!empty($storeSetting->is_enable_withdraw_setting)) {
  397. $finance['balance_cash_service_fee_limit'] = $storeSetting->balance_cash_service_fee_limit;
  398. $finance['balance_cash_service_fee_month'] = $storeSetting->balance_cash_service_fee_month;
  399. $finance['balance_cash_service_fee_diff'] = $storeSetting->balance_cash_service_fee_diff;
  400. $finance['balance_cash_service_fee'] = $storeSetting->balance_cash_service_fee;
  401. }
  402. if(!empty($finance['balance_cash_service_fee_limit'])){
  403. $balance_cash_service_fee_limit = $finance['balance_cash_service_fee_limit'];
  404. $balance_cash_service_fee_month = $finance['balance_cash_service_fee_month'];
  405. $balance_cash_service_fee = $finance['balance_cash_service_fee_diff'] ?? 0;
  406. }else{
  407. if(isset($finance['balance_cash_service_fee'])){
  408. $balance_cash_service_fee = $finance['balance_cash_service_fee'] ?? 0;
  409. }else{
  410. $balance_cash_service_fee = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance.balance_cash_service_fee');
  411. }
  412. }
  413. if (!$cashType) {
  414. return $this->error('系统未设置提现方式');
  415. }
  416. $cash__type_name = [];
  417. $get_system_setting = PlatformSetting::getConfByGroup('system', true);
  418. if (!empty($cashType)) {
  419. $cash_type = $cashType;
  420. $cash__type_name = [];
  421. $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2);
  422. $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY,$this->mall_id,['mall_id'=>$this->mall_id]);
  423. $all_withdraw = array_merge($default_withdraw_way,$extension_withdraw_way);
  424. $cash_type_keys = array_keys($all_withdraw);
  425. if (in_array('bank', $cash_type_keys) || in_array('joinpay', $cash_type_keys)) {
  426. $bank_card_list = StoreBank::lists(['where' => [['store_id' => $this->store_id], ['status' => StatusEnum::ENABLED]], 'select' => 'id,mall_id,store_id,username,bank as bank_name,card_no as bank_card_no']);
  427. }
  428. foreach ($cash_type as $i => $item) {
  429. if (isset($all_withdraw[$item])) {
  430. $taxFee = 0;
  431. $name = '';
  432. if (isset($all_withdraw[$item])) {
  433. if (is_array($all_withdraw[$item])) {
  434. $name = $all_withdraw[$item]['name'] ?? '';
  435. $taxFee = $all_withdraw[$item]['taxFee'] ?? 0;
  436. } else {
  437. $name = $all_withdraw[$item];
  438. }
  439. }
  440. $cash__type_name[$i]['type'] = $item;
  441. $cash__type_name[$i]['taxFee'] = $taxFee;
  442. $cash__type_name[$i]['name'] = $name;
  443. $cash__type_name[$i]['img'] = $get_system_setting['api_url']['value'] . '/resources/img/payment/' . $item . '.png';
  444. if ('bank' == $item || 'joinpay' == $item) {
  445. $cash__type_name[$i]['bank_card_list'] = $bank_card_list;
  446. }
  447. }
  448. }
  449. }
  450. $return = [
  451. 'balance' => $store->balance, //可提现金额
  452. 'unsettled_amount' => $store->unsettled_amount,//待结算金额
  453. // 'store_banks' => $store_banks,
  454. 'balance_cash_service_fee' => $balance_cash_service_fee,
  455. 'balance_cash_service_fee_limit' => $balance_cash_service_fee_limit,
  456. 'balance_cash_service_fee_month' => $balance_cash_service_fee_month,
  457. 'freeze_is_enable' => $freeze_is_enable,
  458. 'finance_name' => $finance_name,
  459. 'user' => $user,
  460. 'cash_type_name' => $cash__type_name,
  461. ];
  462. return $this->success('操作成功', $return,ApiStatusEnum::CODE_SUCCESS,JSON_UNESCAPED_UNICODE);
  463. }
  464. /**
  465. * 添加银行卡
  466. * @return void
  467. */
  468. public function actionAddBankCard()
  469. {
  470. try {
  471. $params = \Yii::$app->request->post();
  472. $res = \Yii::$app->services->validate->validate($params, [
  473. [['username', 'bank', 'card_no'], 'required'],
  474. ['card_no', 'string', 'max' => 64],
  475. [['username'], 'string', 'max' => 50],
  476. [['bank'], 'string', 'max' => 255],
  477. ]);
  478. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  479. $bank_card_info = StoreBank::findONe(['mall_id' => $this->mall_id, 'card_no' => $params['card_no'], 'store_id' => $this->store_id, 'status' => StatusEnum::ENABLED]);
  480. if (!empty($bank_card_info)) {
  481. throw new \Exception('银行卡已经被绑定');
  482. }
  483. $params['mall_id'] = $this->mall_id;
  484. $params['store_id'] = $this->store_id;
  485. $res = StoreBank::setData($params);
  486. if (!$res) throw new \Exception(StoreBank::getStaticError());
  487. return $this->success('添加成功');
  488. } catch (\Exception $exception) {
  489. return $this->error('操作失败:' . $exception->getMessage());
  490. }
  491. }
  492. /**
  493. * 提现
  494. * @throws \Exception
  495. */
  496. public function actionWithdraw()
  497. {
  498. $params = \Yii::$app->request->post();
  499. $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->user_id,'mall_id' => $this->mall_id,'type' => 'cash']);
  500. if($need_auth === true){
  501. //需要先进行实名认证
  502. return $this->error('请先进行实名认证',[],ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
  503. }
  504. $form = new StoreWithdrawLog();
  505. $params['mall_id'] = $this->mall_id;
  506. $params['user_id'] = $this->user_id;
  507. $params['store_id'] = $this->store_id;
  508. $form->attributes = $params;
  509. $data = $form->saveRecord($params);
  510. if ($data['state']) {
  511. return $this->success('操作成功', $data['data']);
  512. } else {
  513. return $this->error($data['msg']);
  514. }
  515. }
  516. }