PurchaseOrderController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\ghs\classes\GhsClass;
  5. use bizGhs\order\classes\PurchaseOrderClass;
  6. use bizGhs\product\classes\ProductClass;
  7. use common\components\util;
  8. use Yii;
  9. class PurchaseOrderController extends BaseController
  10. {
  11. //新增采购订单
  12. public function actionCreateOrder()
  13. {
  14. $post = Yii::$app->request->post();
  15. $post['sjId'] = $this->sjId;
  16. $post['shopId'] = $this->shopId;
  17. $post['adminId'] = $this->adminId;
  18. $post['mainId'] = $this->mainId;
  19. $shop = $this->shop;
  20. $default = $shop->default ?? 0;
  21. if ($default != 1) {
  22. util::fail('请在首店发起采购');
  23. }
  24. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  25. $ghsItemInfo = $post['itemInfo'] ?? '';
  26. if (empty($ghsItemInfo)) {
  27. util::fail('请选择花材');
  28. }
  29. $ghsItemInfo = json_decode($ghsItemInfo, true);
  30. if (!is_array($ghsItemInfo)) {
  31. util::fail('花材格式不正确');
  32. }
  33. //合并
  34. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  35. //判断花材格式,是否属于当前门店
  36. ProductClass::valid($ghsItemInfo, $this->mainId);
  37. //获取供应商信息
  38. $ghsId = $post['ghsId'];
  39. if (empty($ghsId)) {
  40. util::fail("请选择供应商");
  41. }
  42. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  43. GhsClass::valid($ghsInfo, $this->shopId);
  44. $post['ghsInfo'] = json_encode($ghsInfo);
  45. $post['ghsName'] = $ghsInfo['name'] ?? '';
  46. //判断花材里的信息
  47. foreach ($ghsItemInfo as $v) {
  48. $bigNum = $v['bigNum'] ?? 0;
  49. $productId = $v['productId'] ?? 0;
  50. $smallNum = $v['smallNum'] ?? 0;
  51. if (!isset($v['itemPrice'])) {
  52. util::fail('采购价格不能为空');
  53. }
  54. if (!$productId) {
  55. util::fail('花材不存在');
  56. }
  57. if ($bigNum <= 0 && $smallNum <= 0) {
  58. util::fail('花材数量不能为0');
  59. }
  60. }
  61. $post['itemInfo'] = $ghsItemInfo;
  62. $post['debt'] = PurchaseOrderClass::DEBT_YES;
  63. $order = PurchaseOrderClass::addOrder($post);
  64. util::success($order);
  65. util::fail();
  66. }
  67. //订单列表
  68. public function actionList()
  69. {
  70. $get = Yii::$app->request->get();
  71. $orderStatus = $get['status'] ?? '';
  72. if ($orderStatus) {
  73. $where['status'] = $orderStatus;
  74. }
  75. $ghsId = $get['ghsId'] ?? 0;
  76. if (!empty($ghsId)) {
  77. $where['ghsId'] = $ghsId;
  78. }
  79. $where['sjId'] = $this->sjId;
  80. $where['shopId'] = $this->shopId;
  81. $data = PurchaseOrderClass::getOrderList($where);
  82. //状态统计
  83. $statData = PurchaseOrderClass::statNum($this->shopId);
  84. $data = array_merge($data, $statData);
  85. util::success($data);
  86. }
  87. //订单详情
  88. public function actionDetail()
  89. {
  90. $orderSn = Yii::$app->request->get('orderSn', '');
  91. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  92. util::success($orderData);
  93. }
  94. //修改备注
  95. public function actionUpdateRemark()
  96. {
  97. $remark = Yii::$app->request->post('remark', '');
  98. $id = Yii::$app->request->post('id', '');
  99. $cg = PurchaseOrderClass::getById($id, true);
  100. if (empty($cg)) {
  101. util::fail('没有找到订单');
  102. }
  103. if ($cg->shopId != $this->shopId) {
  104. util::fail('没有权限修改');
  105. }
  106. $cg->remark = $remark;
  107. $cg->save();
  108. util::complete('修改成功');
  109. }
  110. }