PurchaseOrderController.php 9.6 KB

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