| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- namespace hd\controllers;
- use bizHd\goods\classes\CategoryClass;
- use bizHd\goods\classes\GoodsClass;
- use bizHd\work\classes\WorkClass;
- use bizHd\work\classes\WorkItemClass;
- use bizHd\work\services\WorkService;
- use common\components\imgUtil;
- use common\components\orderSn;
- use common\components\util;
- use Yii;
- class WorkController extends BaseController
- {
- public $guestAccess = [];
- //工单列表 ssh 20220319
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- 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();
- $post['workSn'] = $orderSn;
- $post['staffId'] = $this->shopAdminId;
- $post['staffName'] = $this->shopAdmin->name;
- $post['name'] = isset($post['name']) && !empty($post['name']) ? $post['name'] : '花束';
- $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;
- $catId = $post['catId'] ?? 0;
- $cat = CategoryClass::getById($catId, true);
- if ($cat->mainId != $this->mainId) {
- util::fail('请选择你自己的分类');
- }
- $post['catName'] = $cat->categoryName ?? '';
- $work = WorkService::createFinish($post);
- $transaction->commit();
- 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;
- $work = WorkClass::goodsCreateFinish($post);
- $transaction->commit();
- util::success(['work' => $work]);
- } 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)) {
- $goods = GoodsClass::getGoodsInfo($goodsId);
- }
- $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_700,w_700";
- $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- 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) {
- WorkClass::lock($work);
- }
- WorkClass::finish($work);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- //打印
- public function actionPrint()
- {
- util::complete();
- }
- }
|