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