| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- namespace hd\controllers;
- use biz\shop\classes\ShopExtClass;
- use bizHd\goods\classes\CategoryClass;
- use bizHd\goods\classes\GoodsClass;
- use bizHd\order\classes\OrderClass;
- use bizHd\work\classes\WorkClass;
- use bizHd\work\classes\WorkItemClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\mtUtil;
- use common\components\orderSn;
- use common\components\util;
- use Shishaoqi\MeituanFlashPurchase\Application;
- use Yii;
- class WorkController extends BaseController
- {
- public $guestAccess = [];
- //根据订单id查询制作单信息 ssh 20220625
- public function actionGetInfoByOrderId()
- {
- $orderId = Yii::$app->request->get('orderId', 0);
- $order = OrderClass::getById($orderId, true);
- OrderClass::valid($order, $this->mainId);
- $info = WorkClass::getByCondition(['orderId' => $orderId], true);
- if (empty($info)) {
- util::fail('没有找到');
- }
- util::success(['info' => $info, 'order' => $order]);
- }
- //打印制作单 ssh 20220601
- public function actionPrint()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $work = WorkClass::getById($id, true);
- WorkClass::valid($work, $this->mainId);
- WorkClass::print($work, $this->shop);
- util::complete();
- }
- //制作单列表 ssh 20220319
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $str = $get['sh'] ?? '';
- if ($str == 'yes') {
- $where['sh'] = 1;
- } else {
- $where['sh'] = 0;
- if (isset($get['fromType']) && is_numeric($get['fromType'])) {
- $where['fromType'] = $get['fromType'];
- } else {
- $shopId = $this->shopId;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- $mtAlone = $ext->mtAlone ?? 0;
- $isCashier = $get['isCashier'] ?? 0;
- if ($mtAlone == 1 && $isCashier == 1) {
- $where['fromType'] = ['in', [0, 1, 2, 3]];
- }
- }
- }
- if (isset($get['sendNum']) && !empty($get['sendNum']) && is_numeric($get['sendNum'])) {
- $where['sendNum'] = $get['sendNum'];
- }
- if (isset($get['thirdSn']) && !empty($get['thirdSn']) && is_numeric($get['thirdSn'])) {
- $where['thirdSn'] = $get['thirdSn'];
- }
- if (isset($get['status']) && $get['status'] >= 0) {
- $status = $get['status'];
- $where['status'] = $status;
- }
- $list = WorkClass::getWorkList($where);
- util::success($list);
- }
- //锁定用材 ssh 20220320
- public function actionLock()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $work = WorkClass::getById($id, true);
- WorkClass::valid($work, $this->mainId);
- WorkItemClass::lock($work);
- util::complete();
- }
- //新建制作单 ssh 20220319
- public function actionCreate()
- {
- $post = Yii::$app->request->post();
- $post['mainId'] = $this->mainId ?? 0;
- $post['sjId'] = $this->sjId ?? 0;
- $post['shopId'] = $this->shopId ?? 0;
- $orderSn = orderSn::getWorkSn();
- $mainId = $this->mainId;
- $post['workSn'] = $orderSn;
- if (isset($post['staffId']) && !empty($post['staffId'])) {
- $staffId = $post['staffId'];
- $staffName = $post['staffName'] ?? '';
- } else {
- $staffId = $this->shopAdminId;
- $staffName = $this->shopAdmin->name;
- }
- $post['staffId'] = $staffId;
- $post['staffName'] = $staffName;
- $post['name'] = isset($post['name']) && !empty($post['name']) ? $post['name'] : '花束';
- $post['cover'] = isset($post['cover']) && !empty($post['cover']) ? $post['cover'] : 'default-img.png';
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $product = $post['product'] ?? '';
- $post['product'] = [];
- if (!empty($product)) {
- $arr = json_decode($product, true);
- if (!empty($arr)) {
- $post['product'] = $arr;
- }
- }
- $post['num'] = isset($post['num']) && $post['num'] > 0 ? $post['num'] : 1;
- $default = CategoryClass::getByCondition(['mainId' => $mainId, 'flower' => 1, 'default' => 1], true);
- if (empty($default)) {
- $catData = [
- 'mainId' => $mainId,
- 'sjId' => $this->sjId,
- 'shopId' => $this->shopId,
- 'default' => 1,
- 'flower' => 1,
- 'categoryName' => '未分类',
- 'inTurn' => 0,
- 'status' => 0,
- ];
- $default = CategoryClass::add($catData, true);
- }
- $catId = $default->id ?? 0;
- if (empty($catId)) {
- util::fail('没有找到分类');
- }
- $post['catId'] = $catId;
- $post['catName'] = $cat->categoryName ?? '';
- $main = $this->main;
- $work = WorkClass::createFinish($post, $main);
- $transaction->commit();
- $complete = $post['complete'] ?? 0;
- $print = $post['print'] ?? 1;
- if ($complete == 1 && $print == 1) {
- WorkClass::print($work, $this->shop, false);
- }
- util::success($work);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- //商品新建制作 ssh 20220320
- public function actionGoodsCreate()
- {
- $post = Yii::$app->request->post();
- $post['mainId'] = $this->mainId ?? 0;
- $post['sjId'] = $this->sjId ?? 0;
- $post['shopId'] = $this->shopId ?? 0;
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $goodsJson = $post['goods'] ?? '';
- $goods = json_decode($goodsJson, true);
- if (empty($goods)) {
- util::fail('没有找到商品');
- }
- $post['goods'] = $goods;
- $main = $this->main;
- WorkClass::goodsCreateFinish($post, $main);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- //包括制作单和用材信息 ssh 20220319
- public function actionFullInfo()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $work = WorkClass::getById($id, true);
- WorkClass::valid($work, $this->mainId);
- $workItem = WorkItemClass::getWorkAllItem($work);
- $goods = [];
- $goodsId = $work->goodsId ?? 0;
- if (!empty($goodsId)) {
- $params = [];
- $shop = $this->shop;
- //这边传的是空的,有影响,后面要解决,请搜索关键词 work_if_need_custom
- $custom = [];
- $goods = GoodsClass::getGoodsInfo($goodsId, $shop, $custom, $params);
- }
- $work = $work->attributes;
- $shortCover = $work['cover'] ?? '';
- $work['shortCover'] = $shortCover;
- $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_1000,w_1000";
- $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $today = date("Y-m-d");
- $tomorrow = date("Y-m-d", strtotime('+1 day'));
- $work['today'] = $today;
- $work['tomorrow'] = $tomorrow;
- $addTime = $work['addTime'] ?? 0;
- $currentTime = strtotime($addTime) + 60;
- $diffTime = bcsub($currentTime, time());
- $beginCount = $diffTime > 0 ? $diffTime : 0;
- $work['beginCount'] = $beginCount;
- util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods]);
- }
- //取消 ssh 20220320
- public function actionCancel()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $work = WorkClass::getById($id, true);
- WorkClass::valid($work, $this->mainId);
- WorkClass::cancel($work);
- util::complete();
- }
- //完成制作单 ssh 20220319
- public function actionFinish()
- {
- $post = Yii::$app->request->post();
- $workId = $post['id'] ?? 0;
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $work = WorkClass::getById($workId, true);
- WorkClass::valid($work, $this->mainId);
- if ($work->status == 1) {
- util::fail('制作单已完成');
- }
- if ($work->status == 2) {
- util::fail('制作单已取消');
- }
- //花材未锁定,需要锁定并扣库存
- if ($work->stockLock == 0) {
- $itemList = $post['itemList'] ?? '';
- if (!empty($itemList)) {
- $product = json_decode($itemList, true);
- if (!empty($product)) {
- WorkItemClass::modifyItem($work, $product);
- WorkItemClass::lock($work);
- }
- }
- }
- $staffId = $post['staffId'] ?? 0;
- if (empty($staffId)) {
- util::fail('请选择制作人');
- }
- $staffName = $post['staffName'] ?? '';
- $staffData = ['staffId' => $staffId, 'staffName' => $staffName];
- WorkClass::finish($work, $staffData);
- $transaction->commit();
- //美团的暂时不打小票
- if ($work->fromType != 4) {
- WorkClass::print($work, $this->shop, false);
- }
- $msg = '已完成';
- $orderId = $work->orderId ?? 0;
- if (!empty($orderId) && $work->fromType == dict::getDict('fromType', 'mt')) {
- $allWork = WorkClass::getAllByCondition(['orderId' => $orderId], null, '*', null, true);
- //订单下如果还有制作单未完成,则不通知美图已经完成拣货
- $allComplete = true;
- if (!empty($allWork)) {
- foreach ($allWork as $current) {
- if ($current->status != 1) {
- $allComplete = false;
- }
- }
- }
- if ($allComplete) {
- $order = OrderClass::getById($orderId, true);
- $thirdOrderId = $order->thirdOrderId ?? '';
- $fromType = $order->fromType ?? 0;
- if (!empty($thirdOrderId) && $fromType == dict::getDict('fromType', 'mt')) {
- // $shopId = $order->shopId ?? 0;
- // $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- // $config = dict::getDict('mtConfig');
- // $app = new Application($config);
- // $accessToken = mtUtil::getAccessToken($ext);
- // $params = ['order_id' => $thirdOrderId, 'access_token' => $accessToken];
- // $mtRes = $app->order->logisticsPush($params);
- // $mtRes = json_decode($mtRes, true);
- // if (isset($mtRes['data']) && $mtRes['data'] == 'ok') {
- // $msg = '已完成,已通知骑手';
- // }
- }
- }
- }
- util::complete($msg);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- }
|