StoreAdminController.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  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\jobs\StoreSyncJob;
  9. use app\models\Admin;
  10. use app\models\Cash;
  11. use app\models\Option;
  12. use app\models\SaasUser;
  13. use app\modules\admin\models\OrderRefundForm;
  14. use app\modules\admin\models\OrderSendForm;
  15. use app\modules\alliance\behaviors\StoreUserAdmin;
  16. use app\modules\alliance\controllers\BaseController;
  17. use app\modules\alliance\models\ShareQrcodeForm;
  18. use app\modules\alliance\models\store\StoreAdminCommentForm;
  19. use app\modules\alliance\models\store\StoreAdminForm;
  20. use app\modules\alliance\models\store\StoreAdminGoodsForm;
  21. use app\modules\alliance\models\store\StoreAdminUserForm;
  22. use app\modules\alliance\models\store\StoreAdminOrderForm;
  23. use app\modules\alliance\controllers\store\Controller;
  24. use app\utils\yunst\src\OrderYunst;
  25. use yii\helpers\ArrayHelper;
  26. use app\models\StoreTemplate;
  27. use app\models\SaasCategory;
  28. use app\models\StoreCash;
  29. use app\models\StoreAccountLog;
  30. use app\models\Store;
  31. use app\utils\OrderNo;
  32. use app\models\SaaSLeaguePriceLog;
  33. class StoreAdminController extends Controller
  34. {
  35. /**
  36. * @return array
  37. */
  38. public function behaviors()
  39. {
  40. return ArrayHelper::merge(parent::behaviors(), [
  41. [
  42. 'class' => StoreUserAdmin::class
  43. ]
  44. ]);
  45. }
  46. /**
  47. * 商品
  48. **/
  49. //管理中心
  50. public function actionStoreInfo(){
  51. $form = new StoreAdminForm();
  52. $form->wechat = $this->wechat;
  53. $form->store_id = $this->store_id;
  54. $res = $form->storeInfo();
  55. return $this->asJson($res);
  56. }
  57. //店铺数据
  58. public function actionShopData()
  59. {
  60. $form = new StoreAdminForm();
  61. $form->start_date = input_params('start_date');
  62. $form->end_date = input_params('end_date');
  63. $form->wechat = $this->wechat;
  64. $form->store_id = $this->store_id;
  65. $form->tab = input_params('tab');
  66. $form->type = input_params('type');
  67. $res = $form->shopData();
  68. return $this->asJson($res);
  69. }
  70. //修改获取商城数据
  71. public function actionGetStoreInfo()
  72. {
  73. $form = new StoreAdminForm();
  74. $form->logo = post_params('logo');
  75. $form->name = post_params('name');
  76. $form->coordinate = post_params('coordinate');
  77. $form->address = post_params('address');
  78. $form->store_id = $this->store_id;
  79. $res = $form->getStoreInfo();
  80. return $this->asJson($res);
  81. }
  82. //店铺数据
  83. public function actionGetYesData()
  84. {
  85. $form = new StoreAdminForm();
  86. $form->start_date = input_params('start_date');
  87. $form->end_date = input_params('end_date');
  88. $form->wechat = $this->wechat;
  89. $form->store_id = $this->store_id;
  90. $res = $form->getYesData();
  91. return $this->asJson($res);
  92. }
  93. //用户列表
  94. public function actionUserList(){
  95. $form = new StoreAdminUserForm();
  96. $attributes = all_params();
  97. $res = $form->userList($this->store_id, $attributes);
  98. return $this->asJson($res);
  99. }
  100. //充值积分或者余额
  101. public function actionUserRecharge() {
  102. $form = new StoreAdminUserForm();
  103. $data = post_params();
  104. $admin = get_admin();
  105. // $admin = json_decode(json_encode(['username' => 'uuu', 'id' => 1]));
  106. return $this->asJson($form->userRecharge($admin, $this->store_id, $data));
  107. }
  108. //商品列表
  109. public function actionGoodsList(){
  110. $form = new StoreAdminGoodsForm();
  111. $form->status = get_params('status',1);
  112. $form->sort = get_params('sort');
  113. $form->store_id = $this->store_id;
  114. $res = $form->goodsList();
  115. return $this->asJson($res);
  116. }
  117. //修改标题
  118. public function actionSetGoodsName(){
  119. $form = new StoreAdminGoodsForm();
  120. $form->id = post_params('id');
  121. $form->goods_name = post_params('name');
  122. $form->store_id = $this->store_id;
  123. $res = $form->setGoodsName();
  124. return $this->asJson($res);
  125. }
  126. //删除商品
  127. public function actionGoodsDel(){
  128. $form = new StoreAdminGoodsForm();
  129. $form->id = post_params('id');
  130. $form->store_id = $this->store_id;
  131. $res = $form->goodsDel();
  132. return $this->asJson($res);
  133. }
  134. //分享商品
  135. public function actionShareGoods(){
  136. $form = new ShareQrcodeForm();
  137. $form->goods_id = post_params('id');
  138. $form->type = 0;
  139. $form->user = get_user();
  140. $form->user_id = get_user_id();
  141. $form->store_id = $this->store_id;
  142. return $this->asJson($form->search());
  143. }
  144. //修改上下架状态
  145. public function actionSetGoodsStatus(){
  146. $form = new StoreAdminGoodsForm();
  147. $form->id = post_params('id');
  148. $form->status = post_params('status');
  149. $form->store_id = $this->store_id;
  150. $res = $form->setGoodsStatus();
  151. return $this->asJson($res);
  152. }
  153. //修改价格库存
  154. public function actionSetGoodsPrice(){
  155. $form = new StoreAdminGoodsForm();
  156. $form->id = post_params('id');
  157. $form->goods_price = post_params('goods_price', 0);
  158. $form->goods_num = post_params('goods_num', 0);
  159. $form->attr = post_params('attr', 0);
  160. $form->store_id = $this->store_id;
  161. $res = $form->setPrice();
  162. return $this->asJson($res);
  163. }
  164. //获取修改商品数据
  165. public function actionGetGoodsEdit(){
  166. $form = new StoreAdminGoodsForm();
  167. $form->id = get_params('id');
  168. $form->store_id = $this->store_id;
  169. $res = $form->getGoodsEdit();
  170. return $this->asJson($res);
  171. }
  172. //获取运费规则
  173. public function actionGetPostageData(){
  174. $form = new StoreAdminGoodsForm();
  175. $res = $form->getPostageData();
  176. return $this->asJson($res);
  177. }
  178. //保存商品
  179. public function actionSaveGoods(){
  180. $form = new StoreAdminGoodsForm();
  181. $form->goods_info = post_params('goods_info');
  182. $form->store_id = $this->store_id;
  183. $res = $form->saveGoods();
  184. return $this->asJson($res);
  185. }
  186. //商品详情
  187. public function actionGoodsDetail(){
  188. $form = new StoreAdminGoodsForm();
  189. $form->id = post_params('id');
  190. $form->store_id = $this->store_id;
  191. $res = $form->goodsDetail();
  192. return $this->asJson($res);
  193. }
  194. //获取商品规格信息
  195. public function actionGetGoodsAttr(){
  196. $form = new StoreAdminGoodsForm();
  197. $form->id = post_params('id');
  198. $form->store_id = $this->store_id;
  199. $res = $form->getGoodsAttr();
  200. return $this->asJson($res);
  201. }
  202. //分类列表
  203. public function actionCatList() {
  204. $form = new StoreAdminGoodsForm();
  205. $form->store_id = $this->store_id;
  206. $res = $form->catList();
  207. return $this->asJson($res);
  208. }
  209. //分类添加保存
  210. public function actionCatSave() {
  211. $form = new StoreAdminGoodsForm();
  212. $form->cat_name = post_params("name");
  213. $form->id = post_params("id");
  214. $form->parent_id = post_params("parent_id", 0);
  215. $form->pic_url = post_params("pic_url");
  216. $form->status = post_params("is_show", 1);
  217. $form->store_id = $this->store_id;
  218. $res = $form->catAdd();
  219. return $this->asJson($res);
  220. }
  221. //分类添加保存
  222. public function actionCatBatchSave() {
  223. $form = new StoreAdminGoodsForm();
  224. $form->store_id = $this->store_id;
  225. $res = $form->catAddBatch(input_params("name_1"), input_params("name_2"), input_params("name_3"));
  226. return $this->asJson($res);
  227. }
  228. //分类修改状态
  229. public function actionSetCatStatus() {
  230. $form = new StoreAdminGoodsForm();
  231. $form->id = post_params("id");
  232. $form->status = post_params("status", 0);
  233. $form->store_id = $this->store_id;
  234. $res = $form->setCatStatus();
  235. return $this->asJson($res);
  236. }
  237. /**
  238. * 订单
  239. */
  240. //订单列表
  241. public function actionOrderList() {
  242. $form = new StoreAdminOrderForm();
  243. $form->status = get_params("status");
  244. $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[
  245. 'begin_time' => get_params("begin_time"),
  246. 'end_time' => get_params("end_time")
  247. ];
  248. $form->store_id = $this->store_id;
  249. $res = $form->orderList();
  250. return $this->asJson($res);
  251. }
  252. //订单商品评价
  253. public function actionOrderCommentGoodsList() {
  254. $form = new StoreAdminCommentForm();
  255. $form->goods_name = get_params("goods_name");
  256. $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[
  257. 'begin_time' => get_params("begin_time"),
  258. 'end_time' => get_params("end_time")
  259. ];
  260. $form->store_id = $this->store_id;
  261. $res = $form->commentGoodsList();
  262. return $this->asJson($res);
  263. }
  264. //订单评价
  265. public function actionOrderCommentList() {
  266. $form = new StoreAdminCommentForm();
  267. $form->goods_name = get_params("goods_name");
  268. $form->goods_id = get_params("goods_id");
  269. $form->status = get_params("status");
  270. $form->type = get_params("type");
  271. $form->store_id = $this->store_id;
  272. $res = $form->commentList();
  273. return $this->asJson($res);
  274. }
  275. //删除评论
  276. public function actionCommentDel() {
  277. $form = new StoreAdminCommentForm();
  278. $form->id = post_params("id");
  279. $form->store_id = $this->store_id;
  280. $res = $form->commentDel();
  281. return $this->asJson($res);
  282. }
  283. //回复评论
  284. public function actionCommentReply() {
  285. $form = new StoreAdminCommentForm();
  286. $form->id = post_params("id");
  287. $form->reply_content = post_params("reply_content");
  288. $form->store_id = $this->store_id;
  289. $res = $form->commentReply();
  290. return $this->asJson($res);
  291. }
  292. //取消订单
  293. public function actionOrderCancel() {
  294. $form = new StoreAdminOrderForm();
  295. $form->remark = post_params("remark");
  296. $form->id = post_params("id");
  297. $form->store_id = $this->store_id;
  298. $res = $form->orderCancel();
  299. return $this->asJson($res);
  300. }
  301. //拒绝取消订单
  302. public function actionOrderRejectCancel() {
  303. $form = new StoreAdminOrderForm();
  304. // $form->remark = post_params("remark");
  305. $form->id = post_params("id");
  306. $form->store_id = $this->store_id;
  307. $res = $form->orderRejectCancel();
  308. return $this->asJson($res);
  309. }
  310. //订单发货
  311. public function actionOrderSend() {
  312. $form = new OrderSendForm();
  313. $post = post_params();
  314. if (($post['is_express'] == OrderSendForm::EXPRESS_TYPE_EXPRESS)) {
  315. $form->scenario = 'EXPRESS';
  316. }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_DADA){
  317. $form->scenario = 'DADA';
  318. }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_UU){
  319. $form->scenario = 'UU';
  320. }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_PEISONG){
  321. $form->scenario = 'PEISONG';
  322. }
  323. $form->attributes = $post;
  324. $form->store_id = $this->store_id;
  325. return $this->asJson($form->save());
  326. }
  327. //售后订单
  328. public function actionOrderRefund() {
  329. $form = new StoreAdminOrderForm();
  330. $form->status = get_params("status", 0);
  331. $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[
  332. 'begin_time' => get_params("begin_time"),
  333. 'end_time' => get_params("end_time")
  334. ];
  335. $form->store_id = $this->store_id;
  336. $res = $form->orderRefund();
  337. return $this->asJson($res);
  338. }
  339. //订单详情
  340. public function actionOrderDetail() {
  341. $form = new StoreAdminOrderForm();
  342. $form->id = post_params("id");
  343. $form->type = post_params("type", 0);
  344. $form->store_id = $this->store_id;
  345. $res = $form->orderDetail();
  346. return $this->asJson($res);
  347. }
  348. //获取快递公司数据
  349. public function actionGetExpress(){
  350. $form = new StoreAdminOrderForm();
  351. $form->store_id = $this->store_id;
  352. $res = $form->express();
  353. return $this->asJson($res);
  354. }
  355. //售后订单处理
  356. public function actionOrderRefundApply() {
  357. $form = new OrderRefundForm();
  358. $form->order_refund_id = post_params("id");
  359. $form->store_id = $this->store_id;
  360. $form->action = post_params("action", 0);
  361. $form->type = post_params("type", 1);
  362. $form->refund = post_params("refund", 0);
  363. $form->address_id = post_params("address_id", 0);
  364. $res = $form->save();
  365. return $this->asJson($res);
  366. }
  367. //售后地址添加
  368. public function actionRefundAddressSave() {
  369. $form = new StoreAdminOrderForm();
  370. $form->id = post_params("id");
  371. $form->mch_name = post_params("name");
  372. $form->mch_mobile = post_params("mobile");
  373. $form->mch_address = post_params("address");
  374. $form->is_default = post_params("is_default", 0);
  375. $form->store_id = $this->store_id;
  376. $res = $form->refundAddressSave();
  377. return $this->asJson($res);
  378. }
  379. //商家收货地址列表
  380. public function actionRefundAddress() {
  381. $form = new StoreAdminOrderForm();
  382. $form->store_id = $this->store_id;
  383. $res = $form->refundAddress();
  384. return $this->asJson($res);
  385. }
  386. //商家收货地址删除
  387. public function actionRefundAddressDel() {
  388. $form = new StoreAdminOrderForm();
  389. $form->id = post_params("id");
  390. $form->store_id = $this->store_id;
  391. $res = $form->refundAddressDel();
  392. return $this->asJson($res);
  393. }
  394. //商家收货地址设置默认
  395. public function actionRefundAddressDefault(){
  396. $form = new StoreAdminOrderForm();
  397. $form->id = post_params("id");
  398. $form->store_id = $this->store_id;
  399. $res = $form->refundAddressDefault();
  400. return $this->asJson($res);
  401. }
  402. //设置订单中的收货地址
  403. public function actionSetRefundAddress(){
  404. $form = new StoreAdminOrderForm();
  405. $form->id = post_params("id");
  406. $form->store_id = $this->store_id;
  407. $form->mch_address = post_params("address_id");
  408. $res = $form->setRefundAddress();
  409. return $this->asJson($res);
  410. }
  411. //获取单个收货地址
  412. public function actionGetAddressInfo(){
  413. $form = new StoreAdminOrderForm();
  414. $form->id = post_params("id");
  415. $form->store_id = $this->store_id;
  416. $res = $form->getAddressInfo();
  417. return $this->asJson($res);
  418. }
  419. /**
  420. * 批量修改价格
  421. */
  422. public function actionUpPriceBatch()
  423. {
  424. $goods_id = input_params('goods_id');
  425. $num = input_params('num');
  426. $form = new \app\modules\admin\models\GoodsForm();
  427. $res = $form->upPriceBatch($goods_id, $num, 'add');
  428. return $this->asJson($res);
  429. }
  430. public function actionTemplateList()
  431. {
  432. $name = input_params('name', '');
  433. $category_id = input_params('category_id', 0);
  434. $cond = ['is_delete' => 0, 'status' => 1];
  435. $name && $cond['name'] = $name;
  436. $category_id && $cond['category_id'] = $category_id;
  437. $query = StoreTemplate::find()->where($cond);
  438. $pagination = pagination_make($query);
  439. $list = $pagination['list'];
  440. foreach($list as &$item){
  441. $item['cat_name'] = '-';
  442. if ($item['category_id'] > 0) {
  443. $cat = SaasCategory::findOne($item['category_id']);
  444. if ($cat) {
  445. $item['cat_name'] = $cat->name;
  446. }
  447. }
  448. $item['home_pic'] = json_decode($item['home_pic'], true);
  449. $item['center_pic'] = json_decode($item['center_pic'], true);
  450. }
  451. $store_template_used = \app\models\Option::get('store_template_used', $this->store_id, 'saas', 0)['value'];
  452. return $this->asJson([
  453. 'code' => 0,
  454. 'msg' => 'success',
  455. 'data' => [
  456. 'store_template_used' => $store_template_used,
  457. 'data' => $list,
  458. 'pageNo' => $pagination['pageNo'],
  459. 'totalCount' => $pagination['totalCount'],
  460. 'sql' => '111'.$query->createCommand()->getRawSql(),
  461. ],
  462. ]);
  463. }
  464. public function actionTemplateInfo()
  465. {
  466. $store_id = $this->store_id;
  467. $id = input_params('id', 0);
  468. $model = StoreTemplate::findOne($id);
  469. $store_template_used = \app\models\Option::get('store_template_used', $store_id, 'saas', 0)['value'];
  470. $used = $store_template_used == $model->id ? 1 : 0;
  471. return $this->asJson([
  472. 'code' => 0,
  473. 'msg' => 'success',
  474. 'data' => $model,
  475. 'used' => $used,
  476. ]);
  477. }
  478. public function actionTemplateUsed()
  479. {
  480. $store_id = $this->store_id;
  481. $id = input_params('id', 0);
  482. $type = input_params('type', ['home']);//home/category/product/center/all
  483. $model = StoreTemplate::findOne($id);
  484. $useTemp = $model->useTemp($store_id, $type);
  485. if($useTemp['code'] != 0){
  486. return $this->asJson($useTemp);
  487. }
  488. if(in_array('all', $type)){
  489. \app\models\Option::set('store_template_used', $id, $store_id, 'saas');
  490. $model->use_count++;
  491. $model->save();
  492. }
  493. return $this->asJson([
  494. 'code' => 0,
  495. 'msg' => 'success',
  496. 'data' => $model,
  497. 'copy' => $useTemp,
  498. ]);
  499. }
  500. public function actionStoreCopyStatus()
  501. {
  502. $id = input_params('id', 0);
  503. $res = \app\models\StoreCopy::doCopyStatus($id);
  504. return $this->asJson($res);
  505. }
  506. //店铺初始化
  507. public function actionStoreInit()
  508. {
  509. $id = input_params("id", 0);
  510. $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value'];
  511. if($default){
  512. $default = json_decode($default, true);
  513. }else{
  514. return $this->asJson([
  515. 'code' => 0,
  516. 'msg' => '暂无默认模板',
  517. ]);
  518. }
  519. // $res = \app\models\StoreCopy::doCopy($default['store_id'], $id, $default['type']);
  520. // return $this->asJson($res);
  521. $id = \queue_push(new StoreSyncJob(['type' => 1, 'to_id' => $id]), 0, 1);
  522. return $this->asJson([
  523. 'code' => 0,
  524. 'msg' => '操作成功',
  525. ]);
  526. }
  527. /**
  528. * 获取提现方式
  529. */
  530. public function actionGetCashMethod()
  531. {
  532. $saas_user = get_saas_user();
  533. $cash_method = [];
  534. if (!empty($saas_user->withdraw_method)) {
  535. $decode = json_decode($saas_user->withdraw_method, true);
  536. if (is_array($decode)) {
  537. $cash_method = $decode;
  538. }
  539. }
  540. return $this->asJson([
  541. 'code' => 0,
  542. 'msg' => 'success',
  543. 'data' => [
  544. 'list' => $cash_method,
  545. ],
  546. ]);
  547. }
  548. /**
  549. * 获取提现方式
  550. */
  551. public function actionDelCashMethod()
  552. {
  553. $saas_user = get_saas_user();
  554. $type = post_params('type');
  555. if (empty($type)) {
  556. return $this->asJson([
  557. 'code' => 1,
  558. 'msg' => '参数错误',
  559. ]);
  560. }
  561. if (empty($saas_user->withdraw_method)) {
  562. return $this->asJson([
  563. 'code' => 0,
  564. 'msg' => '操作成功',
  565. ]);
  566. }
  567. $cash_method = json_decode($saas_user->withdraw_method, true);
  568. if (is_array($cash_method)) {
  569. foreach ($cash_method as $key => $value) {
  570. if ($value['type'] == $type) {
  571. unset($cash_method[$key]);
  572. }
  573. }
  574. $saas_user->withdraw_method = json_encode(array_values($cash_method));
  575. } else {
  576. $saas_user->withdraw_method = '';
  577. }
  578. if ($saas_user->save()) {
  579. return $this->asJson([
  580. 'code' => 0,
  581. 'msg' => '操作成功',
  582. ]);
  583. }
  584. return $this->asJson([
  585. 'code' => 0,
  586. 'msg' => '操作失败',
  587. ]);
  588. }
  589. /**
  590. * 添加提现方式
  591. */
  592. public function actionAddCashMethod()
  593. {
  594. $type = post_params('type');
  595. if (empty($type)) {
  596. return $this->asJson([
  597. 'code' => 1,
  598. 'msg' => '参数错误',
  599. ]);
  600. }
  601. $name = post_params('name');
  602. $account = post_params('account');
  603. $bank = post_params('bank');
  604. if (empty($name) || empty($account)) {
  605. return $this->asJson([
  606. 'code' => 1,
  607. 'msg' => '账号和姓名不能为空',
  608. ]);
  609. }
  610. if ($type == 'bank_card' && empty($bank)) {
  611. return $this->asJson([
  612. 'code' => 1,
  613. 'msg' => '银行不能为空',
  614. ]);
  615. }
  616. $data = [
  617. 'type' => $type,
  618. 'name' => $name,
  619. 'account' => $account,
  620. ];
  621. if ($type == 'bank_card') {
  622. $data['bank'] = $bank;
  623. }
  624. $saas_user = get_saas_user();
  625. if (empty($saas_user->withdraw_method)) {
  626. $saas_user->withdraw_method = json_encode(array_values([$data]));
  627. } else {
  628. $decode = json_decode($saas_user->withdraw_method, true);
  629. if (!$decode) {
  630. $saas_user->withdraw_method = json_encode(array_values([$data]));
  631. } else {
  632. foreach ($decode as $key => $value) {
  633. if ($value['type'] == $type) {
  634. unset($decode[$key]);
  635. break;
  636. }
  637. }
  638. $decode[] = $data;
  639. $saas_user->withdraw_method = json_encode(array_values($decode));
  640. }
  641. }
  642. if ($saas_user->save()) {
  643. return $this->asJson([
  644. 'code' => 0,
  645. 'msg' => '操作成功',
  646. ]);
  647. }
  648. return $this->asJson([
  649. 'code' => 1,
  650. 'msg' => '操作失败',
  651. ]);
  652. }
  653. // 联盟券提现
  654. private function allianceCouponWithdraw($store, $price, $type)
  655. {
  656. if ($price > $store->league_price) {
  657. return $this->asJson([
  658. 'code' => 1,
  659. 'msg' => '提现金额不能大于联盟券余额',
  660. ]);
  661. }
  662. $user_id = get_user_id();
  663. $t = \Yii::$app->db->beginTransaction();
  664. try {
  665. $cash = new StoreCash();
  666. $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_CASH);
  667. $cash->is_delete = 0;
  668. $cash->status = 0;
  669. $cash->price = $price;
  670. $cash->created_at = time();
  671. $cash->user_id = $user_id;
  672. $cash->store_id = $store->id;
  673. $saas_user = get_saas_user();
  674. $cash->saas_id = $saas_user->id;
  675. $withdraw_method = json_decode($saas_user->withdraw_method, true);
  676. if ($withdraw_method) {
  677. $withdraw_method = array_column($withdraw_method, null, 'type');
  678. if ($type == 'wechat') {
  679. $cash->type = 0;
  680. $cash->name = $withdraw_method['wechat']['name'];
  681. $cash->mobile = $withdraw_method['wechat']['account'];
  682. }
  683. if ($type == 'alipay') {
  684. $cash->type = 1;
  685. $cash->name = $withdraw_method['alipay']['name'];
  686. $cash->mobile = $withdraw_method['alipay']['account'];
  687. }
  688. if ($type == 'bank_card') {
  689. $cash->type = 2;
  690. $cash->name = $withdraw_method['bank_card']['name'];
  691. $cash->mobile = $withdraw_method['bank_card']['account'];
  692. $cash->bank_name = $withdraw_method['bank_card']['bank'];
  693. }
  694. }
  695. if ($type == 'wechat_auto') {
  696. $cash->type = 4; // 微信自动打款
  697. }
  698. $cash->pay_time = 0;
  699. $cash->cash_type = StoreCash::CASH_TYPE_ALLIANCE_COUPON;
  700. if (!$cash->save()) {
  701. throw new \Exception('申请失败');
  702. }
  703. $before = $store->league_price;
  704. $store->updateCounters(['league_price' => -floatval($price)]);
  705. \app\models\SaaSLeaguePriceLog::setLeaguePriceLog(
  706. $store->id,
  707. $cash->saas_id,
  708. $cash->price,
  709. $before,
  710. \app\models\SaaSLeaguePriceLog::TYPE_WITHDRAW,
  711. \app\models\SaaSLeaguePriceLog::TAKE_TYPE,
  712. \app\models\SaaSLeaguePriceLog::ROLE_STORE,
  713. $cash->id
  714. );
  715. $t->commit();
  716. return $this->asJson([
  717. 'code' => 0,
  718. 'msg' => '申请成功',
  719. ]);
  720. } catch (\Exception $e) {
  721. $t->rollBack();
  722. return $this->asJson([
  723. 'code' => 1,
  724. 'msg' => '申请失败',
  725. ]);
  726. }
  727. }
  728. //商城账户提现申请
  729. public function actionCashApply() {
  730. $price = post_params('cash');
  731. $type = post_params('type');
  732. $scene = post_params('scene');
  733. if (!$price || !in_array($type, ['alipay', 'bank_card', 'wechat', 'wechat_auto'])) {
  734. return $this->asJson([
  735. 'code' => 1,
  736. 'msg' => '参数非法',
  737. ]);
  738. }
  739. $user_id = get_user_id();
  740. $user = get_user();
  741. $store_id = $this->store_id;
  742. $store = Store::findOne($store_id);
  743. if (!$store) {
  744. return $this->asJson([
  745. 'code' => 1,
  746. 'msg' => '参数非法',
  747. ]);
  748. }
  749. if ($scene == 'allianceCoupon') { // 联盟券提现
  750. return $this->allianceCouponWithdraw($store, $price, $type);
  751. }
  752. if ($store->cusid){
  753. $orderYunst = new OrderYunst();
  754. $res = $orderYunst->queryAcctInfo($store->store_number);
  755. $amount = 0;
  756. if ($res['subCode'] == 'SUCCESS'){
  757. $amount = $res['data']['amount'];//真的
  758. // $amount = 10;//写的假的
  759. }
  760. if ($price > $amount) {
  761. \Yii::error([__METHOD__, $price, $amount]);
  762. return $this->asJson([
  763. 'code' => 1,
  764. 'msg' => '当前大于可提现金额'
  765. ]);
  766. }
  767. }else{
  768. //商城余额是否充足
  769. $storeMoney = \app\models\StoreCash::getMaxCash($store);
  770. if ($price > $storeMoney) {
  771. \Yii::error([__METHOD__, $price, $storeMoney]);
  772. return $this->asJson([
  773. 'code' => 1,
  774. 'msg' => '当前大于可提现金额'
  775. ]);
  776. }
  777. }
  778. $exit = StoreCash::find()->andWhere(['=', 'status', 0])->andWhere(['store_id' => $store_id, 'cash_type' => StoreCash::CASH_TYPE_NORMAL])->exists();
  779. if ($exit) {
  780. \Yii::error([__METHOD__, $store_id, $exit]);
  781. // return $this->asJson([
  782. // 'code' => 1,
  783. // 'msg' => '尚有未完成的提现申请'
  784. // ]);
  785. }
  786. $t = \Yii::$app->db->beginTransaction();
  787. $cash = new StoreCash();
  788. $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_CASH);
  789. $cash->is_delete = 0;
  790. $cash->status = 0;
  791. $cash->price = $price;
  792. $cash->created_at = time();
  793. $cash->user_id = $user_id;
  794. $cash->store_id = $store_id;
  795. $saas_user = get_saas_user();
  796. $cash->saas_id = $saas_user->id;
  797. $withdraw_method = json_decode($saas_user->withdraw_method, true);
  798. if ($withdraw_method) {
  799. $withdraw_method = array_column($withdraw_method, null, 'type');
  800. if ($type == 'wechat') {
  801. $cash->type = 0;
  802. $cash->name = $withdraw_method['wechat']['name'];
  803. $cash->mobile = $withdraw_method['wechat']['account'];
  804. }
  805. if ($type == 'alipay') {
  806. $cash->type = 1;
  807. $cash->name = $withdraw_method['alipay']['name'];
  808. $cash->mobile = $withdraw_method['alipay']['account'];
  809. }
  810. if ($type == 'bank_card') {
  811. $cash->type = 2;
  812. $cash->name = $withdraw_method['bank_card']['name'];
  813. $cash->mobile = $withdraw_method['bank_card']['account'];
  814. $cash->bank_name = $withdraw_method['bank_card']['bank'];
  815. }
  816. }
  817. if ($type == 'wechat_auto') {
  818. $cash->type = 4; // 微信自动打款
  819. }
  820. $cash->pay_time = 0;
  821. if ($cash->save()) {
  822. $subMoney = \app\models\Store::subMoney($store, $price, '商城提现');
  823. if (!$subMoney) {
  824. $t->rollBack();
  825. \Yii::error([__METHOD__, $subMoney, $cash]);
  826. return $this->asJson([
  827. 'code' => 1,
  828. 'msg' => '扣款失败',
  829. ]);
  830. }
  831. $t->commit();
  832. return $this->asJson([
  833. 'code' => 0,
  834. 'msg' => '申请成功'
  835. ]);
  836. } else {
  837. $t->rollBack();
  838. return $this->asJson([
  839. 'code' => 1,
  840. 'msg' => $cash->errors
  841. ]);
  842. }
  843. }
  844. /**
  845. * 提现明细
  846. * @return \yii\web\Response
  847. */
  848. public function actionCashDetail() {
  849. $status = get_params('status', -1);
  850. $saasUser = get_saas_user();
  851. $store_id = $this->store_id;
  852. $cash_type = get_params('cash_type', 0);
  853. if ($cash_type) {
  854. $admin = Admin::findOne(['saas_user_id' => $saasUser->id, 'is_delete' => 0, 'type' => Admin::ADMIN_TYPE_STORE]);
  855. $store = Store::findOne(['id' => $admin->type_id, 'is_delete' => 0]);
  856. $store_id = $store->id;
  857. }
  858. $query = StoreCash::find()->where(['store_id' => $store_id, 'is_delete' => 0]);
  859. if ($status > -1) {
  860. // 待审核
  861. if ($status == 0) {
  862. $query->andWhere(['status' => $status]);
  863. }
  864. // 已审核
  865. if ($status == 1) {
  866. $query->andWhere(['status' => $status]);
  867. }
  868. // 已打款
  869. if ($status == 2) {
  870. $query->andWhere(['in', 'status', [2, 4]]);
  871. }
  872. // 已拒绝
  873. if ($status == 3) {
  874. $query->andWhere(['status' => $status]);
  875. }
  876. }
  877. if (intval($cash_type)) {
  878. $query->andWhere(['cash_type' => $cash_type]);
  879. }
  880. $query->orderBy('id DESC');
  881. $pagination = pagination_make($query);
  882. $list = $pagination['list'];
  883. foreach ($list as &$value) {
  884. $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
  885. $value['audit_time'] = date('Y-m-d H:i:s', $value['updated_at']);
  886. if ($value['status'] == 2 || $value['status'] == 4) {
  887. $value['audit_time'] = date('Y-m-d H:i:s', $value['pay_time']);
  888. }
  889. }
  890. return $this->asJson([
  891. 'code' => 0,
  892. 'msg' => 'success',
  893. 'data' => [
  894. 'list' => $list,
  895. 'pageNo' => $pagination['pageNo'],
  896. 'totalCount' => $pagination['totalCount']
  897. ]
  898. ]);
  899. }
  900. /**
  901. * 获取提现详情
  902. */
  903. public function actionCashDetailInfo()
  904. {
  905. $id = get_params('id');
  906. $store_cash = StoreCash::findOne($id);
  907. if (!$store_cash) {
  908. return $this->asJson([
  909. 'code' => 1,
  910. 'msg' => '提现记录不存在'
  911. ]);
  912. }
  913. // $wechat = getServiceClientWxConfig();
  914. // if (!$wechat) {
  915. // return $this->asJson([
  916. // 'code' => 1,
  917. // 'msg' => '未开启微信提现功能'
  918. // ]);
  919. // }
  920. $platform_mch_appid = Option::get('platform_mch_appid', 0, 'saas')['value'];
  921. $platform_mch_id = Option::get('platform_mch_id', 0, 'saas')['value'];
  922. // $serial_no = Option::get('platform_mch_api_serial_no', 0, 'saas')['value'];
  923. // if (empty($serial_no)) {
  924. // return $this->asJson([
  925. // 'code' => 1,
  926. // 'msg' => '未开启微信提现功能'
  927. // ]);
  928. // }
  929. $saasUser = null;
  930. $name = $store_cash->name ?: '';
  931. if (intval($store_cash->type) === StoreCash::TYPE_WECHAT_AUTO) {
  932. $storeAdmin = Admin::findOne([
  933. 'type' => 'store',
  934. 'type_id' => $store_cash->store_id,
  935. 'is_delete' => 0,
  936. ]);
  937. if ($storeAdmin) {
  938. $saasUser = SaasUser::findOne($storeAdmin->saas_user_id);
  939. if ($saasUser) {
  940. $name = $saasUser->name;
  941. }
  942. }
  943. }
  944. $package = '';
  945. if (!empty($store_cash->wx_cash_result_info)) {
  946. $wx_cash_result_info = json_decode($store_cash->wx_cash_result_info, true);
  947. $package = $wx_cash_result_info['package_info'];
  948. }
  949. $is_user_confirm = 1;
  950. $status = $store_cash->status;
  951. //如果是微信提现且为自动打款
  952. if ($store_cash->type == StoreCash::TYPE_WECHAT_AUTO && $store_cash->status == Cash::STATUS_GIVEN) {
  953. //如果使用的是微信新版打款方式
  954. if (1 || intval($store_cash->wx_cash_type)) {
  955. //如果微信新版状态是等待用户确认
  956. if ($store_cash->wx_cash_state == 'WAIT_USER_CONFIRM') {
  957. $is_user_confirm = 0;
  958. if ($saasUser->id != get_saas_user_id()) {
  959. $is_user_confirm = 1;
  960. }
  961. // $status = Cash::STATUS_CONFIRM;
  962. }
  963. }
  964. }
  965. $price = StoreCash::getServiceMoney($store_cash);
  966. $data = [
  967. 'type' => StoreCash::$type[$store_cash->type],//提现方式
  968. 'status' => $status,//提现状态
  969. 'order_no' => $store_cash->order_no,
  970. 'created_at' => date('Y-m-d H:i:s', $store_cash->created_at),
  971. 'updated_at' => $store_cash->updated_at > 0 ? date('Y-m-d H:i:s', $store_cash->updated_at) : '',
  972. 'name' => $name,
  973. 'appid' => $platform_mch_appid,
  974. 'mch_id' => $platform_mch_id,
  975. 'package' => $package,
  976. 'is_user_confirm' => $is_user_confirm,
  977. 'price' => $price,
  978. ];
  979. return $this->asJson([
  980. 'code' => 0,
  981. 'msg' => 'success',
  982. 'data' => $data
  983. ]);
  984. }
  985. //商城账户余额信息
  986. public function actionStoreMoney() {
  987. $store_id = $this->store_id;
  988. $store = \app\models\Store::findOne($store_id);
  989. $data = [];
  990. $maxMoney = StoreCash::getMaxCash($store, $data);
  991. // 已提现
  992. $moneyCash = StoreCash::find()->where(['store_id' => $store->id, 'is_delete' => 0, 'status' => 2, 'cash_type' => StoreCash::CASH_TYPE_NORMAL])
  993. ->andWhere(['>', 'price', 0])
  994. ->sum('price');
  995. $yunstFreeZenAmount = 0;
  996. $yunstMaxMoney = 0;
  997. $yunstMoneyTotal = 0;
  998. if ($store->cusid){
  999. //查询余额账户信息
  1000. $orderYunst = new OrderYunst();
  1001. // print_r(111);die;
  1002. $res = $orderYunst->queryAcctInfo($store->store_number);
  1003. // $res = $orderYunst->queryAcctInfo('XDQXCJSZPJYB');
  1004. // print_r($res);die;
  1005. if ($res['subCode']=='SUCCESS' ){
  1006. // print_r($res);die;
  1007. $yunstFreeZenAmount = $res['data']['freezenAmount'];//冻结
  1008. $amount = $res['data']['amount'];//可用余额
  1009. if (($yunstFreeZenAmount + $amount) >0){
  1010. $yunstMoneyTotal = ($yunstFreeZenAmount + $amount) / 100;
  1011. }else{
  1012. $yunstMoneyTotal = 0;
  1013. }
  1014. $yunstFreeZenAmount = $yunstFreeZenAmount? $yunstFreeZenAmount/100 : 0;;//冻结
  1015. $yunstMaxMoney = $amount?$amount/100:0;//账户总金额 可提现的
  1016. }
  1017. }
  1018. return $this->asJson([
  1019. 'code' => 0,
  1020. 'msg' => 'ok',
  1021. 'data' => [
  1022. 'max_cash' => $maxMoney,//总计提现
  1023. 'moneyFrozen' => $data['moneyFrozen'],//冻结金额
  1024. 'moneyCash' => $moneyCash,//可提现
  1025. 'moneyTotal' => bcadd($data['storeMoneyTotal'], $yunstMoneyTotal, 2),//累计金额
  1026. 'yunstFreeZenAmount' => $yunstFreeZenAmount,//通联冻结
  1027. 'yunstMaxMoney' => $yunstMaxMoney,//通联账户总金额
  1028. 'yunstMoneyTotal' => $yunstMoneyTotal, //通联冻结+账户可提现
  1029. 'league_price' => $store->league_price,
  1030. ]
  1031. ]);
  1032. }
  1033. /**
  1034. * 商城账户明细列表
  1035. * @return \yii\web\Response
  1036. */
  1037. public function actionStoreAccountLogList() {
  1038. $store_id = $this->store_id;
  1039. $start_time = get_params('start_time');
  1040. $end_time = get_params('end_time');
  1041. $type = get_params('type');
  1042. $query = StoreAccountLog::find()->alias('c');
  1043. $store_id > 0 && $query->andWhere(['c.store_id' => $store_id]);
  1044. if ($start_time) {
  1045. $query->andWhere(['>=', 'c.time', strtotime($start_time)]);
  1046. }
  1047. if ($end_time) {
  1048. $query->andWhere(['<=', 'c.time', strtotime($end_time)]);
  1049. }
  1050. if ($type > 0) {
  1051. $query->andWhere(['c.type' => $type]);
  1052. }
  1053. $query->orderBy('c.id DESC');
  1054. $pagination = pagination_make($query);
  1055. $list = $pagination['list'];
  1056. return $this->asJson([
  1057. 'code' => 0,
  1058. 'msg' => 'success',
  1059. 'data' => [
  1060. 'data' => $list,
  1061. 'pageNo' => $pagination['pageNo'],
  1062. 'totalCount' => $pagination['totalCount']
  1063. ],
  1064. ]);
  1065. }
  1066. /**
  1067. * 获取商城溢价
  1068. */
  1069. public function actionStoreSetting() {
  1070. $form = new StoreAdminForm();
  1071. $form->store_id = $this->store_id;
  1072. $form->rate = post_params('rate');
  1073. // $form->is_auth_trans = post_params('is_auth_trans');
  1074. $form->cloud_is_update = post_params('cloud_is_update');
  1075. $res = $form->storeSetting();
  1076. return $this->asJson($res);
  1077. }
  1078. //核销支付宝商家券
  1079. public function actionClerkAlipayVoucher() {
  1080. $form = new \app\modules\admin\models\alipay\Ordervoucher();
  1081. $form->mini_id = get_mini_id();
  1082. $form->store_id = get_store_id();
  1083. $form->user_id = get_user_id();
  1084. $total_price = post_params('total_price', 100);
  1085. $ov = post_params('ov', '');
  1086. $submit = post_params('submit', 1);
  1087. $res = $form->use($submit, $ov, $total_price);
  1088. return $this->asJson($res);
  1089. }
  1090. //扫码入库
  1091. public function actionErpScanGetGoodsList() {
  1092. $form = new StoreAdminGoodsForm();
  1093. $form->attributes = get_params();
  1094. $form->store_id = $this->store_id;
  1095. $res = $form->erpScanGetGoodsList();
  1096. return $this->asJson($res);
  1097. }
  1098. //erp入库
  1099. public function actionPurchaseInSave() {
  1100. $form = new StoreAdminGoodsForm();
  1101. $form->attributes = all_params();
  1102. $form->store_id = $this->store_id;
  1103. $res = $form->purchaseInSave();
  1104. return $this->asJson($res);
  1105. }
  1106. }