PurchaseOrderController.php 6.6 KB

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