PurchaseOrderController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. //判断花材里的信息
  117. foreach ($ghsItemInfo as $v) {
  118. $bigNum = $v['bigNum'] ?? 0;
  119. $productId = $v['productId'] ?? 0;
  120. $smallNum = $v['smallNum'] ?? 0;
  121. if (!isset($v['itemPrice'])) {
  122. util::fail('采购价格不能为空');
  123. }
  124. if (!$productId) {
  125. util::fail('花材不存在');
  126. }
  127. if ($bigNum <= 0 && $smallNum <= 0) {
  128. util::fail('花材数量不能为0');
  129. }
  130. }
  131. $post['itemInfo'] = $ghsItemInfo;
  132. $post['debt'] = PurchaseOrderClass::DEBT_YES;
  133. $order = PurchaseOrderClass::addOrder($post);
  134. util::success($order);
  135. util::fail();
  136. }
  137. //订单列表
  138. public function actionList()
  139. {
  140. $get = Yii::$app->request->get();
  141. $orderStatus = $get['status'] ?? '';
  142. if ($orderStatus) {
  143. $where['status'] = $orderStatus;
  144. }
  145. $ghsId = $get['ghsId'] ?? 0;
  146. if (!empty($ghsId)) {
  147. $where['ghsId'] = $ghsId;
  148. }
  149. $where['sjId'] = $this->sjId;
  150. $where['shopId'] = $this->shopId;
  151. $data = PurchaseOrderClass::getOrderList($where);
  152. //状态统计
  153. $statData = PurchaseOrderClass::statNum($this->shopId);
  154. $data = array_merge($data, $statData);
  155. util::success($data);
  156. }
  157. //订单详情
  158. public function actionDetail()
  159. {
  160. $orderSn = Yii::$app->request->get('orderSn', '');
  161. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  162. util::success($orderData);
  163. }
  164. //修改备注
  165. public function actionUpdateRemark()
  166. {
  167. $remark = Yii::$app->request->post('remark', '');
  168. $id = Yii::$app->request->post('id', '');
  169. $cg = PurchaseOrderClass::getById($id, true);
  170. if (empty($cg)) {
  171. util::fail('没有找到订单');
  172. }
  173. if ($cg->shopId != $this->shopId) {
  174. util::fail('没有权限修改');
  175. }
  176. $cg->remark = $remark;
  177. $cg->save();
  178. util::complete('修改成功');
  179. }
  180. }