SupplierController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers\cloud;
  8. use app\models\Admin;
  9. use app\models\Share;
  10. use yii\base\BaseObject;
  11. use yii\helpers\Json;
  12. use app\jobs\BatchDownGoodsJob;
  13. use app\constants\OptionSetting;
  14. use app\models\Option;
  15. //use linslin\yii2\curl;
  16. use app\modules\admin\controllers\BaseController;
  17. use app\modules\admin\models\SupplierForm;
  18. use app\modules\alliance\models\purchase\order\OrderForm;
  19. use app\modules\alliance\models\purchase\order\OrderListForm;
  20. use app\models\PurchaseOrder;
  21. use app\modules\admin\controllers\cloud\behaviors\SupplierBehaviors;
  22. use yii\helpers\ArrayHelper;
  23. use app\constants\Kefu;
  24. use app\models\Supplier;
  25. use app\models\Store;
  26. class SupplierController extends BaseController
  27. {
  28. /**
  29. * @return array
  30. */
  31. public function behaviors()
  32. {
  33. return ArrayHelper::merge(parent::behaviors(), [
  34. [
  35. 'class' => SupplierBehaviors::class
  36. ]
  37. ]);
  38. }
  39. //获取运费规则
  40. public function actionSupplierGetRules(){
  41. $post = post_params();
  42. $form = new SupplierForm();
  43. $form->attributes = $post;
  44. $this->asJson($form->supplierGetRules());
  45. }
  46. //删除运费规则
  47. public function actionSupplierDelRules(){
  48. $post = post_params();
  49. $form = new SupplierForm();
  50. $form->attributes = $post;
  51. $this->asJson($form->supplierDelRules());
  52. }
  53. //删除运费规则
  54. public function actionSupplierSetStatus(){
  55. $post = post_params();
  56. $form = new SupplierForm();
  57. $form->attributes = $post;
  58. $this->asJson($form->supplierSetStatus());
  59. }
  60. //获取运费规则列表
  61. public function actionSupplierGetRulesList(){
  62. $post = post_params();
  63. $form = new SupplierForm();
  64. $form->attributes = $post;
  65. $this->asJson($form->supplierGetRulesList());
  66. }
  67. //订单取消审核
  68. // public function actionSupplierOrderCancel(){
  69. // $post = post_params();
  70. // $form = new SupplierForm();
  71. // $form->attributes = $post;
  72. // $this->asJson($form->supplierOrderCancel());
  73. // }
  74. //订单取消审核
  75. public function actionSupplierOrderRevoke(){
  76. $form = new OrderForm();
  77. $form->attributes = post_params();
  78. // $form->delete_pass = 1;
  79. // $form->remark = '';
  80. $cloud_order_id = (string)post_params('order_id', 0);
  81. $order = PurchaseOrder::find()->where(['cloud_order_id' => $cloud_order_id, 'is_delete' => 0])->one();
  82. if (!$order) {
  83. return $this->asJson([
  84. 'code' => 1,
  85. 'msg' => '订单不存在'
  86. ]);
  87. }
  88. return $this->asJson($form->revokeApply($order));
  89. }
  90. //供货单修改收货地址 / 卖家备注
  91. public function actionSupplierOrderSetAddress(){
  92. $post = post_params();
  93. $form = new SupplierForm();
  94. $form->attributes = $post;
  95. $this->asJson($form->supplierOrderSetAddress());
  96. }
  97. //转单修改收货地址 / 卖家备注
  98. public function actionSupplierPurchaseOrderSetAddress(){
  99. $post = post_params();
  100. $form = new SupplierForm();
  101. $form->attributes = $post;
  102. $this->asJson($form->supplierPurchaseOrderSetAddress());
  103. }
  104. //供货单发货
  105. public function actionSupplierOrderSend(){
  106. $post = post_params();
  107. $form = new SupplierForm();
  108. $form->attributes = $post;
  109. $this->asJson($form->supplierOrderSend());
  110. }
  111. //供货单xlsx发货
  112. public function actionSupplierOrderXlsxSend(){
  113. $post = post_params();
  114. $form = new SupplierForm();
  115. $form->attributes = $post;
  116. $this->asJson($form->supplierOrderSend());
  117. }
  118. //供货单列表
  119. public function actionSupplierOrderList(){
  120. $post = post_params();
  121. $form = new SupplierForm();
  122. $form->attributes = $post;
  123. $this->asJson(OrderListForm::appendOrderInfo($form->supplierOrderList()));
  124. }
  125. //供货单列表
  126. public function actionSupplierSendTypeList(){
  127. $post = post_params();
  128. $form = new SupplierForm();
  129. $form->attributes = $post;
  130. $this->asJson(OrderListForm::appendOrderInfo($form->supplierSendTypeList()));
  131. }
  132. //云仓库存列表
  133. public function actionGetCloudPreviewNum(){
  134. $post = get_params();
  135. $form = new SupplierForm();
  136. $form->attributes = $post;
  137. $this->asJson($form->getCloudPreviewNum());
  138. }
  139. //云仓库存详情
  140. public function actionGetCloudPreviewNumInfo(){
  141. $post = get_params();
  142. $form = new SupplierForm();
  143. $form->attributes = $post;
  144. $this->asJson($form->getCloudPreviewNumInfo());
  145. }
  146. //订单取消审核
  147. public function actionSupplierPurchaseCancel(){
  148. $post = post_params();
  149. $form = new SupplierForm();
  150. $form->attributes = $post;
  151. $this->asJson($form->supplierPurchaseCancel());
  152. }
  153. //订单发货
  154. public function actionSupplierPurchaseSend(){
  155. $post = post_params();
  156. $form = new SupplierForm();
  157. $form->attributes = $post;
  158. $this->asJson($form->supplierPurchaseSend());
  159. }
  160. //订单发货
  161. public function actionUpdateOrderSendInfo(){
  162. $post = post_params();
  163. $form = new SupplierForm();
  164. $form->attributes = $post;
  165. $this->asJson($form->updateOrderSendInfo());
  166. }
  167. //订单删除
  168. public function actionSupplierPurchaseDel(){
  169. $post = post_params();
  170. $form = new SupplierForm();
  171. $form->attributes = $post;
  172. $this->asJson($form->supplierPurchaseDel());
  173. }
  174. //订单删除
  175. public function actionSupplierOrderDel(){
  176. $post = post_params();
  177. $form = new SupplierForm();
  178. $form->attributes = $post;
  179. $this->asJson($form->supplierOrderDel());
  180. }
  181. //转单列表
  182. public function actionSupplierPurchaseOrderList(){
  183. $post = post_params();
  184. $form = new SupplierForm();
  185. $form->attributes = $post;
  186. $this->asJson($form->supplierPurchaseOrderList());
  187. }
  188. //转单售后列表
  189. public function actionSupplierPurchaseOrderRefundList(){
  190. $post = post_params();
  191. $form = new SupplierForm();
  192. $form->attributes = $post;
  193. $this->asJson($form->supplierPurchaseOrderRefundList());
  194. }
  195. //转单售后列表
  196. public function actionSupplierSendTypeRefundList(){
  197. $post = post_params();
  198. $form = new SupplierForm();
  199. $form->attributes = $post;
  200. $this->asJson($form->supplierSendTypeRefundList());
  201. }
  202. //处理退换货请求
  203. public function actionSupplierApplyHandle()
  204. {
  205. $post = post_params();
  206. $form = new SupplierForm();
  207. $form->attributes = $post;
  208. $this->asJson($form->supplierApplyHandle());
  209. }
  210. //供货商提现申请
  211. public function actionSetSupplierCash(){
  212. $post = post_params();
  213. $form = new SupplierForm();
  214. $form->attributes = $post;
  215. $this->asJson($form->storeSetSupplierCash());
  216. }
  217. //余额记录
  218. public function actionSupplierGetBalanceLog(){
  219. $post = post_params();
  220. $form = new SupplierForm();
  221. $form->attributes = $post;
  222. $this->asJson($form->supplierGetBalanceLog());
  223. }
  224. //余额冻结记录
  225. public function actionSupplierGetBalanceFrozenLog(){
  226. $post = post_params();
  227. $form = new SupplierForm();
  228. $form->attributes = $post;
  229. $this->asJson($form->supplierGetBalanceFrozenLog());
  230. }
  231. //编辑运费
  232. public function actionSetRules(){
  233. $post = post_params();
  234. $form = new SupplierForm();
  235. $form->attributes = $post;
  236. $this->asJson($form->setRules());
  237. }
  238. //提交审核
  239. public function actionAuditSubmit(){
  240. $post = post_params();
  241. $form = new SupplierForm();
  242. $form->attributes = $post;
  243. $this->asJson($form->auditSubmit());
  244. }
  245. //商品上下架操作
  246. public function actionSetGoodsStatus(){
  247. $post = post_params();
  248. $form = new SupplierForm();
  249. $form->attributes = $post;
  250. $this->asJson($form->setGoodsStatus());
  251. }
  252. //添加编辑规格
  253. public function actionSetGoodsAttr(){
  254. $post = post_params();
  255. $form = new SupplierForm();
  256. $form->attributes = $post;
  257. $this->asJson($form->setGoodsAttr());
  258. }
  259. //创建编辑商品
  260. public function actionSetGoods(){
  261. $post = post_params();
  262. $form = new SupplierForm();
  263. $form->attributes = $post;
  264. $this->asJson($form->setGoods());
  265. }
  266. //获取供货商商品列表
  267. public function actionGoodsList(){
  268. $post = post_params();
  269. $form = new SupplierForm();
  270. $form->attributes = $post;
  271. $this->asJson($form->goodsList());
  272. }
  273. //获取供货商商品列表
  274. public function actionGoodsAuditList(){
  275. $post = post_params();
  276. $form = new SupplierForm();
  277. $form->attributes = $post;
  278. $this->asJson($form->goodsAuditList());
  279. }
  280. //获取供货商转单订单详情
  281. public function actionPurchaseOrderInfo(){
  282. $post = get_params();
  283. $form = new SupplierForm();
  284. $form->attributes = $post;
  285. // $this->asJson($form->purchaseOrderInfo(111));
  286. $form->purchaseOrderInfo(get_params("order_id"), get_params("supplier_id"));
  287. }
  288. //获取集采列表
  289. public function actionAgentOrderGroupList(){
  290. $post = get_params();
  291. $form = new SupplierForm();
  292. $form->attributes = $post;
  293. $this->asJson($form->agentOrderGroupList());
  294. }
  295. //生成配货单
  296. public function actionAgentOrderDistribution() {
  297. $post = post_params();
  298. $form = new SupplierForm();
  299. $form->attributes = $post;
  300. $this->asJson($form->agentOrderDistribution());
  301. }
  302. //配送单列表
  303. public function actionAgentOrderDistributionList() {
  304. $post = get_params();
  305. $form = new SupplierForm();
  306. $form->attributes = $post;
  307. $this->asJson($form->agentOrderDistributionList());
  308. }
  309. //更改配货单状态
  310. public function actionSetDistributionStatus() {
  311. $post = post_params();
  312. $form = new SupplierForm();
  313. $form->attributes = $post;
  314. $this->asJson($form->setDistributionStatus());
  315. }
  316. public function actionGetKefuInfo()
  317. {
  318. $supplier = Supplier::findOne(get_supplier_id());
  319. if (!$supplier) {
  320. return $this->asJson([
  321. 'code' => 1,
  322. 'msg' => '数据不存在',
  323. ]);
  324. }
  325. return $this->asJson([
  326. 'code' => 0,
  327. 'msg' => 'success',
  328. 'data'=> [
  329. 'kefu_id' => $supplier->kefu_id ?: '',
  330. ]
  331. ]);
  332. }
  333. public function actionSetKefuInfo()
  334. {
  335. $kefu_id = \post_params('kefu_id');
  336. $supplier = Supplier::findOne(get_supplier_id());
  337. if (!$supplier) {
  338. return $this->asJson([
  339. 'code' => 1,
  340. 'msg' => '数据不存在',
  341. ]);
  342. }
  343. if (!empty($kefu_id)) {
  344. $url = Kefu::API_HOST;
  345. $host = \str_replace(['http://', 'https://'], '', \Yii::$app->request->hostInfo);
  346. $res = http_post($url . '/api/regKefu', [
  347. 'form_params' => [
  348. 'token' => \Yii::$app->getKefuApiToken(),
  349. 'host' => $host,
  350. 'mobile' => $kefu_id,
  351. ]
  352. ]);
  353. if ($res->getStatusCode() != 200) {
  354. return $this->asJson([
  355. 'code' => 1,
  356. 'msg' => '请求出错!',
  357. ]);
  358. }
  359. $content = json_decode((string)$res->getBody(), true);
  360. if ($content['code'] == 0) {
  361. $supplier->kefu_id = $kefu_id;
  362. $supplier->save();
  363. }
  364. } else {
  365. $supplier->kefu_id = '';
  366. $supplier->save();
  367. $content = [
  368. 'code' => 0,
  369. 'msg' => '保存成功',
  370. ];
  371. }
  372. return $this->asJson($content);
  373. }
  374. /**
  375. * 修改价格
  376. * @return mixed
  377. */
  378. public function actionModifyPrice()
  379. {
  380. $form = new SupplierForm();
  381. $form->attributes = post_params();
  382. return $this->asJson($form->modifyPrice());
  383. }
  384. //获取仓库采购订单
  385. public function actionPurchaseList() {
  386. $form = new \app\modules\admin\models\agent\front_erp\PurchaseForm();
  387. // $admin = get_admin();
  388. // if (!$admin) {
  389. // return $this->asJson([
  390. // 'code' => 1,
  391. // 'msg' => '需要登录'
  392. // ]);
  393. // }
  394. // if ($admin->type !== Admin::ADMIN_TYPE_SUPPLIER) {
  395. // return $this->asJson([
  396. // 'code' => 1,
  397. // 'msg' => '当前供货商身份验证失败'
  398. // ]);
  399. // }
  400. $form->admin_supplier_id = get_supplier_id();
  401. $form->attributes = post_params();
  402. return $this->asJson($form->search());
  403. }
  404. //获取仓库采购订单
  405. public function actionPurchaseInfo() {
  406. $form = new \app\modules\admin\models\agent\front_erp\PurchaseForm();
  407. // $admin = get_admin();
  408. // if (!$admin) {
  409. // return $this->asJson([
  410. // 'code' => 1,
  411. // 'msg' => '需要登录'
  412. // ]);
  413. // }
  414. // if ($admin->type !== Admin::ADMIN_TYPE_SUPPLIER) {
  415. // return $this->asJson([
  416. // 'code' => 1,
  417. // 'msg' => '当前供货商身份验证失败'
  418. // ]);
  419. // }
  420. $form->admin_supplier_id = get_supplier_id();
  421. $form->attributes = all_params();
  422. return $this->asJson($form->info());
  423. }
  424. //打印仓库采购订单
  425. public function actionPrintPurchase() {
  426. $form = new \app\modules\admin\models\agent\front_erp\PurchaseForm();
  427. $form->admin_supplier_id = get_supplier_id();
  428. $form->attributes = all_params();
  429. $res = $form->searchPurchase();
  430. return $this->asJson($res);
  431. }
  432. //供货商修改采购订单状态(发货)
  433. public function actionSetPurchaseOrderStatus() {
  434. $form = new \app\modules\admin\models\agent\front_erp\PurchaseForm();
  435. // $admin = get_admin();
  436. // if (!$admin) {
  437. // return $this->asJson([
  438. // 'code' => 1,
  439. // 'msg' => '需要登录'
  440. // ]);
  441. // }
  442. // if ($admin->type !== Admin::ADMIN_TYPE_SUPPLIER) {
  443. // return $this->asJson([
  444. // 'code' => 1,
  445. // 'msg' => '当前供货商身份验证失败'
  446. // ]);
  447. // }
  448. $form->admin_supplier_id = get_supplier_id();
  449. $form->attributes = all_params();
  450. return $this->asJson($form->setPurchaseOrderStatus());
  451. }
  452. }