PurchaseOrderController.php 3.6 KB

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