PurchaseController.php 4.3 KB

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