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