PurchaseOrderController.php 3.6 KB

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