PurchaseOrderController.php 8.2 KB

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