| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- <?php
- namespace ghs\controllers;
- use biz\admin\classes\AdminRoleClass;
- use biz\ghs\classes\GhsClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\order\classes\PurchaseOrderItemClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\noticeUtil;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class PurchaseOrderController extends BaseController
- {
- //打印全部 ssh 20220602
- public function actionPrintAll()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? 0;
- $type = $get['type'] ?? 0;
- $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (empty($itemList)) {
- util::fail('没有商品');
- }
- $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
- $mainId = $order->mainId ?? 0;
- $ext = $this->shopExt;
- $printLabelSn = $ext->printLabelSn ?? '';
- if (empty($printLabelSn)) {
- util::fail('请设置标签打印机');
- }
- $p = new printUtil($printLabelSn);
- foreach ($itemList as $key => $item) {
- $name = $item->name ?? '';
- $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
- if (empty($num)) {
- util::fail('没有花材数量');
- }
- $ptItemId = $item->itemId ?? '';
- $productId = $item->productId ?? 0;
- $p->times = $num;
- $smallUnit = $item->smallUnit ?? '';
- $bigUnit = $item->bigUnit ?? '';
- $ratio = $item->ratio ?? 0;
- $unit = $ratio . $smallUnit . '/' . $bigUnit;
- if(isset($item->ratioType) && $item->ratioType == 1){
- $unit = '若干' . $smallUnit . '/' . $bigUnit;
- }
- if (stringUtil::getWordNum($name) > 7) {
- $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
- } else {
- $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
- }
- if ($key % 2 == 1) {
- $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="0">.</TEXT>';
- }
- if ($type == 0) {
- $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $ptItemId . '</BC128>';
- if (in_array($mainId, [52, 1459])) {
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
- } else {
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
- }
- } else {
- $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
- $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
- }
- $p->printLabelMsg($content);
- }
- util::complete();
- }
- //打印全部 ssh 20220
- public function actionPrintItem()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $type = $get['type'] ?? 0;
- $item = PurchaseOrderItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- $name = $item->name ?? '';
- $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
- if (empty($num)) {
- util::fail('没有花材数量');
- }
- $orderSn = $item->orderSn ?? '';
- $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
- $mainId = $order->mainId ?? 0;
- $ext = $this->shopExt;
- $printLabelSn = $ext->printLabelSn ?? '';
- if (empty($printLabelSn)) {
- util::fail('请设置标签打印机');
- }
- $p = new printUtil($printLabelSn);
- $productId = $item->productId ?? 0;
- $product = ProductClass::getById($productId, true);
- $smallUnit = $product->smallUnit ?? '';
- $bigUnit = $product->bigUnit ?? '';
- $ratio = $product->ratio ?? 20;
- $ratioType = $product->ratioType ?? 0;
- if ($ratioType == 1) {
- $unit = '若干' . $smallUnit . '/' . $bigUnit;
- } else {
- $unit = $ratio . $smallUnit . '/' . $bigUnit;
- }
- $ptItemId = $item->itemId ?? '';
- $p->times = $num;
- if (stringUtil::getWordNum($name) > 7) {
- $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
- } else {
- $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
- }
- if ($type == 0) {
- $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $ptItemId . '</BC128>';
- if (in_array($mainId, [52, 1459])) {
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
- } else {
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
- }
- } else {
- $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
- $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
- }
- $p->printLabelMsg($content);
- util::complete();
- }
- //取消入库单 ssh 20221211
- public function actionCancel()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cg = PurchaseOrderClass::getLockById($id);
- if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
- util::fail('请确认是否您的采购单');
- }
- if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_CANCEL) {
- util::fail('已取消过了');
- }
- if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
- util::fail('已入库,无法取消');
- }
- $cg->status = PurchaseOrderClass::PURCHASE_ORDER_STATUS_CANCEL;
- $cg->save();
- util::complete();
- }
- //确认入库 sssh 20221211
- public function actionConfirmPutIn()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cg = PurchaseOrderClass::getLockById($id);
- if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
- util::fail('请确认是否您的采购单');
- }
- $staff = $this->shopAdmin;
- $data = [];
- $data['staffId'] = $staff->id ?? 0;
- $data['staffName'] = $staff->name ?? '';
- $data['adminId'] = $this->adminId ?? 0;
- $return = PurchaseOrderClass::putIn($cg, $data);
- $transaction->commit();
- util::success($return);
- } catch (\Exception $e) {
- $transaction->rollBack();
- noticeUtil::push('确认入库失败,原因:' . $e->getMessage(), '15280215347');
- Yii::error("确认入库失败,原因:" . $e->getMessage());
- util::fail('确认失败');
- }
- }
- //新增采购订单
- public function actionCreateOrder()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $post['mainId'] = $this->mainId;
- $staff = $this->shopAdmin;
- $post['staffId'] = $staff->id ?? 0;
- $post['staffName'] = $staff->name ?? '';
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- $shop = $this->shop;
- $carSale = $shop->carSale ?? 0;
- if ($carSale == 1) {
- util::fail('车销不能采购');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
- $ghsItemInfo = $post['itemInfo'] ?? '';
- if (empty($ghsItemInfo)) {
- util::fail('请选择花材');
- }
- $ghsItemInfo = json_decode($ghsItemInfo, true);
- if (!is_array($ghsItemInfo)) {
- util::fail('花材格式不正确');
- }
- //合并
- $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
- //判断花材格式,是否属于当前门店
- ProductClass::valid($ghsItemInfo, $this->mainId);
- //获取供货商信息
- $ghsId = $post['ghsId'];
- if (empty($ghsId)) {
- util::fail("请选择供货商");
- }
- $ghsInfo = GhsClass::getGhsInfo($ghsId);
- GhsClass::valid($ghsInfo, $this->shopId);
- $post['ghsInfo'] = json_encode($ghsInfo);
- $post['ghsName'] = $ghsInfo['name'] ?? '';
- $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
- //判断花材里的信息
- foreach ($ghsItemInfo as $v) {
- $bigNum = $v['bigNum'] ?? 0;
- $productId = $v['productId'] ?? 0;
- $smallNum = $v['smallNum'] ?? 0;
- if (!isset($v['itemPrice'])) {
- util::fail('采购价格不能为空');
- }
- if (!$productId) {
- util::fail('花材不存在');
- }
- if ($bigNum <= 0 && $smallNum <= 0) {
- util::fail('花材数量不能为0');
- }
- }
- $post['itemInfo'] = $ghsItemInfo;
- //0稍后入库 1直接入库
- $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
- $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
- $post['debt'] = $debtStatus;
- $order = PurchaseOrderClass::addOrder($post);
- $transaction->commit();
- util::success($order);
- } catch (\Exception $e) {
- $transaction->rollBack();
- noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
- Yii::error("操作失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- //订单列表
- public function actionList()
- {
- if (getenv('YII_ENV') == 'production') {
- //阿东的创始人才能查看采购单
- if (in_array($this->mainId, [742])) {
- $staff = $this->shopAdmin;
- if ($staff->founder != 2 && in_array($staff->id, [126647]) == false) {
- util::fail('没有权限');
- }
- }
- }
- $get = Yii::$app->request->get();
- $orderStatus = $get['status'] ?? '';
- if ($orderStatus) {
- $where['status'] = $orderStatus;
- }
- $ghsId = $get['ghsId'] ?? 0;
- if (!empty($ghsId)) {
- $where['ghsId'] = $ghsId;
- }
- $where['sjId'] = $this->sjId;
- $where['shopId'] = $this->shopId;
- $data = PurchaseOrderClass::getOrderList($where);
- //状态统计,很慢,暂时隐藏
- //$statData = PurchaseOrderClass::statNum($this->shopId);
- $statData = [
- 'allNum' => 0,
- 'unPayNum' => 0,
- 'unSendNum' => 0,
- 'sendingNum' => 0,
- 'finishNum' => 0,
- ];
- $data = array_merge($data, $statData);
- util::success($data);
- }
- //订单详情
- public function actionDetail()
- {
- if (getenv('YII_ENV') == 'production') {
- //阿东的创始人才能查看采购单
- if (in_array($this->mainId, [742])) {
- $staff = $this->shopAdmin;
- if ($staff->founder != 2 && in_array($staff->id, [126647]) == false) {
- util::fail('没有权限');
- }
- }
- }
- $orderSn = Yii::$app->request->get('orderSn', '');
- $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
- util::success($orderData);
- }
- //修改备注
- public function actionUpdateRemark()
- {
- $remark = Yii::$app->request->post('remark', '');
- $id = Yii::$app->request->post('id', '');
- $cg = PurchaseOrderClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到订单');
- }
- if ($cg->shopId != $this->shopId) {
- util::fail('没有权限修改');
- }
- $cg->remark = $remark;
- $cg->save();
- util::complete('修改成功');
- }
- }
|