PurchaseOrderController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. noticeUtil::push($unit, '15280215347');
  49. }
  50. util::complete();
  51. }
  52. //打印全部 ssh 20220
  53. public function actionPrintItem()
  54. {
  55. $get = Yii::$app->request->get();
  56. $id = $get['id'] ?? 0;
  57. $item = PurchaseOrderItemClass::getById($id, true);
  58. if (empty($item)) {
  59. util::fail('没有找到花材');
  60. }
  61. $name = $item->name ?? '';
  62. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  63. if (empty($num)) {
  64. util::fail('没有花材数量');
  65. }
  66. $ext = $this->shopExt;
  67. $printLabelSn = $ext->printLabelSn ?? '';
  68. if (empty($printLabelSn)) {
  69. util::fail('请设置标签打印机');
  70. }
  71. $p = new printUtil($printLabelSn);
  72. $smallUnit = $item->smallUnit ?? '';
  73. $bigUnit = $item->bigUnit ?? '';
  74. $unit = $smallUnit . '/' . $bigUnit;
  75. $ptItemId = $item->itemId ?? '';
  76. $p->times = $num;
  77. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  78. $content .= '<BC128 x="260" y="30" h="80" s="1" r="90" n="5" w="12">' . $ptItemId . '</BC128>';
  79. $content .= '<TEXT x="60" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
  80. $p->printLabelMsg($content);
  81. util::complete();
  82. }
  83. //新增采购订单
  84. public function actionCreateOrder()
  85. {
  86. $post = Yii::$app->request->post();
  87. $post['sjId'] = $this->sjId;
  88. $post['shopId'] = $this->shopId;
  89. $post['adminId'] = $this->adminId;
  90. $post['mainId'] = $this->mainId;
  91. $shopAdmin = $this->shopAdmin;
  92. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  93. util::fail('超管才能修改');
  94. }
  95. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  96. $ghsItemInfo = $post['itemInfo'] ?? '';
  97. if (empty($ghsItemInfo)) {
  98. util::fail('请选择花材');
  99. }
  100. $ghsItemInfo = json_decode($ghsItemInfo, true);
  101. if (!is_array($ghsItemInfo)) {
  102. util::fail('花材格式不正确');
  103. }
  104. //合并
  105. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  106. //判断花材格式,是否属于当前门店
  107. ProductClass::valid($ghsItemInfo, $this->mainId);
  108. //获取供应商信息
  109. $ghsId = $post['ghsId'];
  110. if (empty($ghsId)) {
  111. util::fail("请选择供应商");
  112. }
  113. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  114. GhsClass::valid($ghsInfo, $this->shopId);
  115. $post['ghsInfo'] = json_encode($ghsInfo);
  116. $post['ghsName'] = $ghsInfo['name'] ?? '';
  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. $get = Yii::$app->request->get();
  142. $orderStatus = $get['status'] ?? '';
  143. if ($orderStatus) {
  144. $where['status'] = $orderStatus;
  145. }
  146. $ghsId = $get['ghsId'] ?? 0;
  147. if (!empty($ghsId)) {
  148. $where['ghsId'] = $ghsId;
  149. }
  150. $where['sjId'] = $this->sjId;
  151. $where['shopId'] = $this->shopId;
  152. $data = PurchaseOrderClass::getOrderList($where);
  153. //状态统计
  154. $statData = PurchaseOrderClass::statNum($this->shopId);
  155. $data = array_merge($data, $statData);
  156. util::success($data);
  157. }
  158. //订单详情
  159. public function actionDetail()
  160. {
  161. $orderSn = Yii::$app->request->get('orderSn', '');
  162. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  163. util::success($orderData);
  164. }
  165. //修改备注
  166. public function actionUpdateRemark()
  167. {
  168. $remark = Yii::$app->request->post('remark', '');
  169. $id = Yii::$app->request->post('id', '');
  170. $cg = PurchaseOrderClass::getById($id, true);
  171. if (empty($cg)) {
  172. util::fail('没有找到订单');
  173. }
  174. if ($cg->shopId != $this->shopId) {
  175. util::fail('没有权限修改');
  176. }
  177. $cg->remark = $remark;
  178. $cg->save();
  179. util::complete('修改成功');
  180. }
  181. }