PurchaseOrderController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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\order\classes\PurchaseOrderItemClass;
  7. use bizGhs\product\classes\ProductClass;
  8. use common\components\noticeUtil;
  9. use common\components\printUtil;
  10. use common\components\util;
  11. use Yii;
  12. class PurchaseOrderController extends BaseController
  13. {
  14. //打印全部 ssh 20220602
  15. public function actionPrintAll()
  16. {
  17. $get = Yii::$app->request->get();
  18. $orderSn = $get['orderSn'] ?? 0;
  19. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  20. if (empty($itemList)) {
  21. util::fail('没有商品');
  22. }
  23. $ext = $this->shopExt;
  24. $printLabelSn = $ext->printLabelSn ?? '';
  25. if (empty($printLabelSn)) {
  26. util::fail('请设置标签打印机');
  27. }
  28. $p = new printUtil($printLabelSn);
  29. foreach ($itemList as $key => $item) {
  30. $name = $item->name ?? '';
  31. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  32. if (empty($num)) {
  33. util::fail('没有花材数量');
  34. }
  35. $ptItemId = $item->itemId ?? '';
  36. $p->times = $num;
  37. $smallUnit = $item->smallUnit ?? '';
  38. $bigUnit = $item->bigUnit ?? '';
  39. $ratio = $item->ratio ?? 0;
  40. $unit = $ratio . $smallUnit . '/' . $bigUnit;
  41. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  42. $content .= '<BC128 x="260" y="30" h="80" s="1" r="90" n="5" w="12">' . $ptItemId . '</BC128>';
  43. if ($key % 2 == 1) {
  44. $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="90">.</TEXT>';
  45. }
  46. $content .= '<TEXT x="60" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
  47. $p->printLabelMsg($content);
  48. }
  49. util::complete();
  50. }
  51. //打印全部 ssh 20220
  52. public function actionPrintItem()
  53. {
  54. $get = Yii::$app->request->get();
  55. $id = $get['id'] ?? 0;
  56. $item = PurchaseOrderItemClass::getById($id, true);
  57. if (empty($item)) {
  58. util::fail('没有找到花材');
  59. }
  60. $name = $item->name ?? '';
  61. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  62. if (empty($num)) {
  63. util::fail('没有花材数量');
  64. }
  65. $ext = $this->shopExt;
  66. $printLabelSn = $ext->printLabelSn ?? '';
  67. if (empty($printLabelSn)) {
  68. util::fail('请设置标签打印机');
  69. }
  70. $p = new printUtil($printLabelSn);
  71. $smallUnit = $item->smallUnit ?? '';
  72. $bigUnit = $item->bigUnit ?? '';
  73. $unit = $smallUnit . '/' . $bigUnit;
  74. $ptItemId = $item->itemId ?? '';
  75. $p->times = $num;
  76. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  77. $content .= '<BC128 x="260" y="30" h="80" s="1" r="90" n="5" w="12">' . $ptItemId . '</BC128>';
  78. $content .= '<TEXT x="60" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
  79. $p->printLabelMsg($content);
  80. util::complete();
  81. }
  82. //新增采购订单
  83. public function actionCreateOrder()
  84. {
  85. $post = Yii::$app->request->post();
  86. $post['sjId'] = $this->sjId;
  87. $post['shopId'] = $this->shopId;
  88. $post['adminId'] = $this->adminId;
  89. $post['mainId'] = $this->mainId;
  90. $shopAdmin = $this->shopAdmin;
  91. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  92. util::fail('超管才能修改');
  93. }
  94. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  95. $ghsItemInfo = $post['itemInfo'] ?? '';
  96. if (empty($ghsItemInfo)) {
  97. util::fail('请选择花材');
  98. }
  99. $ghsItemInfo = json_decode($ghsItemInfo, true);
  100. if (!is_array($ghsItemInfo)) {
  101. util::fail('花材格式不正确');
  102. }
  103. //合并
  104. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  105. //判断花材格式,是否属于当前门店
  106. ProductClass::valid($ghsItemInfo, $this->mainId);
  107. //获取供货商信息
  108. $ghsId = $post['ghsId'];
  109. if (empty($ghsId)) {
  110. util::fail("请选择供货商");
  111. }
  112. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  113. GhsClass::valid($ghsInfo, $this->shopId);
  114. $post['ghsInfo'] = json_encode($ghsInfo);
  115. $post['ghsName'] = $ghsInfo['name'] ?? '';
  116. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  117. //判断花材里的信息
  118. foreach ($ghsItemInfo as $v) {
  119. $bigNum = $v['bigNum'] ?? 0;
  120. $productId = $v['productId'] ?? 0;
  121. $smallNum = $v['smallNum'] ?? 0;
  122. if (!isset($v['itemPrice'])) {
  123. util::fail('采购价格不能为空');
  124. }
  125. if (!$productId) {
  126. util::fail('花材不存在');
  127. }
  128. if ($bigNum <= 0 && $smallNum <= 0) {
  129. util::fail('花材数量不能为0');
  130. }
  131. }
  132. $post['itemInfo'] = $ghsItemInfo;
  133. $post['debt'] = PurchaseOrderClass::DEBT_YES;
  134. $order = PurchaseOrderClass::addOrder($post);
  135. util::success($order);
  136. util::fail();
  137. }
  138. //订单列表
  139. public function actionList()
  140. {
  141. if (getenv('YII_ENV') == 'production') {
  142. //阿东的创始人才能查看采购单
  143. if (in_array($this->mainId, [742])) {
  144. $staff = $this->shopAdmin;
  145. if (isset($staff->founder) == false || $staff->founder != 2) {
  146. util::fail('没有权限');
  147. }
  148. }
  149. } else {
  150. if (in_array($this->mainId, [644])) {
  151. $staff = $this->shopAdmin;
  152. if (isset($staff->founder) == false || $staff->founder != 2) {
  153. util::fail('没有权限');
  154. }
  155. }
  156. }
  157. $get = Yii::$app->request->get();
  158. $orderStatus = $get['status'] ?? '';
  159. if ($orderStatus) {
  160. $where['status'] = $orderStatus;
  161. }
  162. $ghsId = $get['ghsId'] ?? 0;
  163. if (!empty($ghsId)) {
  164. $where['ghsId'] = $ghsId;
  165. }
  166. $where['sjId'] = $this->sjId;
  167. $where['shopId'] = $this->shopId;
  168. $data = PurchaseOrderClass::getOrderList($where);
  169. //状态统计
  170. $statData = PurchaseOrderClass::statNum($this->shopId);
  171. $data = array_merge($data, $statData);
  172. util::success($data);
  173. }
  174. //订单详情
  175. public function actionDetail()
  176. {
  177. if (getenv('YII_ENV') == 'production') {
  178. //阿东的创始人才能查看采购单
  179. if (in_array($this->mainId, [742])) {
  180. $staff = $this->shopAdmin;
  181. if (isset($staff->founder) == false || $staff->founder != 2) {
  182. util::fail('没有权限');
  183. }
  184. }
  185. }
  186. $orderSn = Yii::$app->request->get('orderSn', '');
  187. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  188. util::success($orderData);
  189. }
  190. //修改备注
  191. public function actionUpdateRemark()
  192. {
  193. $remark = Yii::$app->request->post('remark', '');
  194. $id = Yii::$app->request->post('id', '');
  195. $cg = PurchaseOrderClass::getById($id, true);
  196. if (empty($cg)) {
  197. util::fail('没有找到订单');
  198. }
  199. if ($cg->shopId != $this->shopId) {
  200. util::fail('没有权限修改');
  201. }
  202. $cg->remark = $remark;
  203. $cg->save();
  204. util::complete('修改成功');
  205. }
  206. }