PurchaseController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. $shop = $this->shop;
  73. $pfLevel = $shop->pfLevel ?? 0;
  74. $respond['pfLevel'] = $pfLevel;
  75. util::success($respond);
  76. }
  77. //批量确认 ssh 20240518
  78. public function actionBatchConfirm()
  79. {
  80. if (getenv('YII_ENV') == 'production') {
  81. //小向花卉采购的结账确认,有多处,关键词ghs_cg_clear_confirm
  82. if (in_array($this->mainId, [23390, 24516])) {
  83. if (!in_array($this->adminId, [24655, 77951])) {
  84. util::fail('不能操作哦');
  85. }
  86. }
  87. } else {
  88. if (in_array($this->shopId, [36523])) {
  89. // if (!in_array($this->adminId, [919])) {
  90. // util::fail('不能操作哈');
  91. // }
  92. }
  93. }
  94. $post = Yii::$app->request->post();
  95. $str = $post['id'] ?? 0;
  96. $ghsId = $post['ghsId'] ?? 0;
  97. if (empty($str)) {
  98. util::fail('没有选择订单');
  99. }
  100. $arr = json_decode($str, true);
  101. $ids = array_column($arr, 'id');
  102. if (empty($ids)) {
  103. util::fail('没有订单哦');
  104. }
  105. $list = PurchaseOrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  106. if (empty($list)) {
  107. util::fail('没有订单');
  108. }
  109. foreach ($list as $order) {
  110. if ($order->ghsId != $ghsId) {
  111. util::fail('订单有问题');
  112. }
  113. $order->confirm = 1;
  114. $order->save();
  115. }
  116. util::complete('确认成功');
  117. }
  118. }