PurchaseOrderController.php 3.5 KB

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