PurchaseController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use bizGhs\custom\classes\CustomClass;
  5. use bizGhs\order\classes\PurchaseOrderClass;
  6. use bizGhs\order\services\PurchaseOrderService;
  7. use bizGhs\product\classes\ProductClass;
  8. use bizHd\purchase\classes\PurchaseClass;
  9. use common\components\dateUtil;
  10. use common\components\util;
  11. use Yii;
  12. class PurchaseController extends BaseController
  13. {
  14. public $guestAccess = ['get-cg-salt'];
  15. /**
  16. * 分享跳转花店采购详情时,按 xhCg 主键取 salt(无需登录)
  17. */
  18. public function actionGetCgSalt()
  19. {
  20. $get = Yii::$app->request->get();
  21. $id = intval($get['id'] ?? 0);
  22. if (empty($id)) {
  23. util::fail('采购单无效');
  24. }
  25. $cg = PurchaseClass::getById($id, true);
  26. if (empty($cg)) {
  27. util::fail('没有找到采购单');
  28. }
  29. $payDate = substr($cg->payTime ?? '', 0, 10);
  30. //2026年6月1号前的可以取这个数据,之后的不行
  31. if ($payDate >= '2026-06-01') {
  32. util::fail('该分享链接已失效');
  33. }
  34. $salt = $cg->salt ?? '';
  35. if (empty($salt)) {
  36. util::fail('采购单信息无效');
  37. }
  38. util::success(['salt' => $salt]);
  39. }
  40. // 批发商开单限购花材信息
  41. public function actionLimitBuyInfo()
  42. {
  43. $post = Yii::$app->request->post();
  44. $customId = $post['customId'] ?? 0;
  45. $list = $post['list'] ?? [];
  46. if (empty($customId)) {
  47. util::fail('缺少客户');
  48. }
  49. if (empty($list) || !is_array($list)) {
  50. util::fail('请选择花材');
  51. }
  52. $custom = CustomClass::getCustom($customId);
  53. if (empty($custom)) {
  54. util::fail('没有找到客户');
  55. }
  56. CustomClass::valid($custom, $this->shopId);
  57. $respond = ProductClass::getLimitBuyInfoByList($list, $customId);
  58. util::success($respond);
  59. }
  60. //待结款明细 ssh 2021.1.26
  61. public function actionDebtList()
  62. {
  63. $get = Yii::$app->request->get();
  64. $id = $get['id'] ?? 0;
  65. $confirm = $get['confirm'] ?? -1;
  66. $shortOrderSn = $get['shortOrderSn'] ?? '';
  67. $info = GhsClass::getGhsInfo($id);
  68. GhsClass::valid($info, $this->shopId);
  69. $where = ['ghsId' => $id, 'debt' => PurchaseOrderClass::DEBT_YES];
  70. if ($confirm > -1) {
  71. $where['confirm'] = $confirm;
  72. }
  73. $searchTime = $get['searchTime'] ?? '';
  74. if (!empty($searchTime)) {
  75. $startTime = $get['startTime'] ?? '';
  76. $endTime = $get['endTime'] ?? '';
  77. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  78. $where['entryTime'] = ['between', [$period['startTime'], $period['endTime']]];
  79. }
  80. if (!empty($shortOrderSn)) {
  81. $where['orderSn'] = ['like', $shortOrderSn];
  82. }
  83. $respond = PurchaseOrderService::getDebtList($where);
  84. $respond['ghsInfo'] = $info;
  85. util::success($respond);
  86. }
  87. //批量确认 ssh 20240518
  88. public function actionBatchConfirm()
  89. {
  90. if (getenv('YII_ENV') == 'production') {
  91. //小向花卉采购的结账确认,有多处,关键词ghs_cg_clear_confirm
  92. if (in_array($this->mainId, [23390, 24516])) {
  93. if (!in_array($this->adminId, [24655,77951])) {
  94. util::fail('不能操作哦');
  95. }
  96. }
  97. } else {
  98. if (in_array($this->shopId, [36523])) {
  99. // if (!in_array($this->adminId, [919])) {
  100. // util::fail('不能操作哈');
  101. // }
  102. }
  103. }
  104. $post = Yii::$app->request->post();
  105. $str = $post['id'] ?? 0;
  106. $ghsId = $post['ghsId'] ?? 0;
  107. if (empty($str)) {
  108. util::fail('没有选择订单');
  109. }
  110. $arr = json_decode($str, true);
  111. $ids = array_column($arr, 'id');
  112. if (empty($ids)) {
  113. util::fail('没有订单哦');
  114. }
  115. $list = PurchaseOrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  116. if (empty($list)) {
  117. util::fail('没有订单');
  118. }
  119. foreach ($list as $order) {
  120. if ($order->ghsId != $ghsId) {
  121. util::fail('订单有问题');
  122. }
  123. $order->confirm = 1;
  124. $order->save();
  125. }
  126. util::complete('确认成功');
  127. }
  128. }