| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- <?php
- namespace ghs\controllers;
- use bizGhs\book\classes\BookCustomClass;
- use bizGhs\book\classes\BookItemClass;
- use bizGhs\book\classes\BookItemCustomClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\OrderItemClass;
- use bizGhs\order\services\OrderItemService;
- use bizGhs\order\services\OrderService;
- use bizGhs\product\classes\ProductClass;
- use common\components\imgUtil;
- use common\components\util;
- use Yii;
- class OrderItemController extends BaseController
- {
- public $guestAccess = [];
- //过滤名称 ssh 20240430
- public function actionFilterName()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = OrderItemClass::getById($id, true);
- $name = $info->name ?? '';
- $num = $info->xhNum ?? 0;
- $name = strtolower($name);
- $name = preg_replace('/\d/', '', $name);
- $arr = ['cm', '箱', '个', 'a', 'b', 'c', 'd', 'e', 'o', '梦金鹏', '拍市', '七彩', '市场', '(', ')', '(', ')', '-', '级', '红', '黄', '绿', '橙', '蓝', '基地', '支', '枝', '*', '张良', '配色', '混色', '浅粉', '粉', '玫红', '青铜', '深紫', '浅紫', '紫', '色', '重瓣', ' ', ' '];
- foreach ($arr as $it) {
- $name = str_replace($it, '', $name);
- }
- util::success(['name' => $name, 'num' => $num]);
- }
- //修改预订单花材的数量和价格
- public function actionModifyBookItem()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $data = $post['data'] ?? [];
- $packCost = $post['packCost'] ?? 0;
- $sendCost = $post['sendCost'] ?? 0;
- if (empty($data)) {
- util::fail('没有花材数据');
- }
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单哦');
- }
- if ($order->stockChange == 1) {
- util::fail('已经入库,不能修改');
- }
- if ($order->status != 2) {
- util::fail('待发货订单才能修改');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $addData = [];
- $delData = [];
- foreach ($data as $item) {
- $id = $item['id'] ?? 0;
- $xhNum = $item['xhNum'] ?? 0;
- $xhUnitPrice = $item['xhUnitPrice'] ?? 0;
- $info = OrderItemClass::getById($id, true);
- if (empty($info)) {
- continue;
- }
- if ($info->orderSn != $order->orderSn) {
- continue;
- }
- $productId = $info->productId ?? 0;
- $preNum = $info->xhNum ?? 0;
- //新增预订花材
- if ($xhNum > $preNum) {
- $diffNum = bcsub($xhNum, $preNum);
- $addData[] = [
- 'productId' => $productId,
- 'num' => $diffNum,
- 'lastNum' => $xhNum,
- ];
- }
- //删除预订花材
- if ($preNum > $xhNum) {
- $diffNum = bcsub($preNum, $xhNum);
- $delData[] = [
- 'productId' => $productId,
- 'num' => $diffNum,
- 'lastNum' => $xhNum,
- ];
- }
- $info->xhNum = $xhNum;
- $info->xhPreNum = $xhNum;
- $info->xhUnitPrice = $xhUnitPrice;
- $info->xhPreUnitPrice = $xhUnitPrice;
- $info->save();
- }
- $order->packCost = $packCost;
- $order->sendCost = $sendCost;
- $order->save();
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
- if (!empty($addData)) {
- BookItemClass::addBatchItem($addData, $order, $params);
- }
- if (!empty($delData)) {
- BookItemClass::delBathItem($delData, $order, $params);
- }
- $transaction->commit();
- util::complete('保存成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("保存出错了:" . $e->getMessage());
- util::fail('保存出错了');
- }
- }
- //更换花材 ssh 20240430
- public function actionChangeItem()
- {
- $post = Yii::$app->request->post();
- $delId = $post['delId'] ?? 0;
- $orderSn = $post['orderSn'] ?? '';
- $num = $post['num'] ?? 0;
- $price = $post['price'] ?? 0;
- $productId = $post['productId'] ?? 0;
- $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($order)) {
- util::fail('订单没有找到哦');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- $delInfo = OrderItemClass::getById($delId, true);
- if (empty($delInfo)) {
- util::fail('没有找到要删除的花材');
- }
- if ($delInfo->orderSn != $orderSn) {
- util::fail('这个花材你不能删除');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- OrderItemClass::delBookItem($order, $delId);
- $new = [];
- $new[$productId] = ['num' => $num, 'productId' => $productId, 'price' => $price];
- OrderItemClass::addBookItemFn($order, $new);
- $transaction->commit();
- util::complete('更换成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("出错了:" . $e->getMessage());
- util::fail('出错了');
- }
- }
- //删除花材 ssh 20240123
- public function actionDelItem()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $smallId = $post['smallId'] ?? 0;
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有订单');
- }
- if ($order->status != 2) {
- util::fail('待发货才能添加');
- }
- if ($order->book == 0) {
- util::fail('不是预订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- if (floatval($order->actPrice) != 0) {
- util::fail('订单金额不是0');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
- OrderItemClass::delBookItem($order, $smallId, $params);
- $transaction->commit();
- util::complete('删除成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("删除出错了:" . $e->getMessage());
- util::fail('删除出错了');
- }
- }
- //添加花材
- public function actionAddItem()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $data = $post['data'] ?? 0;
- $arr = json_decode($data, true);
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有订单');
- }
- if ($order->status != 2) {
- util::fail('待发货才能添加');
- }
- if ($order->book == 0) {
- util::fail('不是预订单');
- }
- if (floatval($order->actPrice) != 0) {
- util::fail('订单金额不是0');
- }
- if (empty($arr)) {
- util::fail('请选花材');
- }
- $new = [];
- foreach ($arr as $val) {
- $id = $val['id'] ?? 0;
- $num = $val['bigCount'] ?? 0;
- $name = $val['name'] ?? '';
- $price = $val['price'] ?? 0;
- if ($num <= 0) {
- util::fail($name . ' 数量要大于0');
- }
- $new[$id] = ['num' => $num, 'productId' => $id, 'price' => $price];
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,];
- OrderItemClass::addBookItemFn($order, $new, $params);
- $transaction->commit();
- util::complete('添加成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("添加出错了:" . $e->getMessage());
- util::fail('添加出错了');
- }
- }
- //赠送花材 ssh 20230411
- public function actionGiveItem()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $num = $post['num'] ?? 0;
- if (is_numeric($num) == false || $num <= 0) {
- util::fail('请填写赠送数量');
- }
- $orderItem = OrderItemClass::getById($id, true);
- if (empty($orderItem)) {
- util::fail('没有找到花材');
- }
- if ($orderItem->mainId != $this->mainId) {
- util::fail('无法操作');
- }
- if (!in_array($this->mainId, [1496])) {
- util::fail('开发中');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $staffId = $staff->id ?? 0;
- $data = ['shopId' => $this->shopId, 'sjId' => $this->sjId, 'staffName' => $staffName, 'staffId' => $staffId];
- $respond = OrderItemService::giveProduct($data, $orderItem, $num);
- $transaction->commit();
- util::success(['info' => $respond], '赠送成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("赠送出错了:" . $e->getMessage());
- util::fail('出错了');
- }
- }
- //重选花材 ssh 2021.3.2
- public function actionReset()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $product = $post['product'] ?? '[]';
- $product = json_decode($product, true);
- //检查花材是否都是同家门店的
- ProductClass::valid($product, $this->mainId);
- $info = OrderService::getOrderInfo($id);
- OrderClass::valid($info, $this->shopId);
- //添加修改花材
- $orderSn = $info['orderSn'] ?? '';
- OrderItemClass::replaceItem($orderSn, $product);
- util::complete();
- }
- //修改花材时获取订单花材和花材基本信息的组合 ssh 20210809
- public function actionGetOrderProduct()
- {
- $id = Yii::$app->request->get('id', 0);
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- $orderSn = $order->orderSn ?? '';
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', 'productId');
- $ids = array_column($itemList, 'productId');
- if (empty($ids)) {
- util::fail('没有找到花材');
- }
- $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
- if (empty($productList)) {
- util::fail('没有找到花材信息');
- }
- foreach ($productList as $key => $product) {
- $productId = $product['id'] ?? 0;
- $currentItem = $itemList[$productId] ?? [];
- $bigCount = $currentItem['bigNum'] ?? 0;
- $smallCount = $currentItem['smallNum'] ?? 0;
- $userPrice = $currentItem['userPrice'] ?? 0;
- $productList[$key]['bigCount'] = $bigCount;
- $productList[$key]['smallCount'] = $smallCount;
- $productList[$key]['userPrice'] = $userPrice;
- $cover = imgUtil::groupImg($product['cover']);
- $productList[$key]['cover'] = $cover;
- $bigPrice = $product['unitPrice'] ?? 0;
- $smallPrice = $product['smallUnitPrice'] ?? 0;
- $productList[$key]['bigPrice'] = $bigPrice;
- $productList[$key]['smallPrice'] = $smallPrice;
- $productList[$key]['cover'] = $cover;
- }
- util::success(['productList' => array_values($productList)]);
- }
- //根据花材id取订单列表 ssh 20211011
- public function actionGetOrderInfoList()
- {
- $get = Yii::$app->request->get();
- $productId = $get['productId'] ?? 0;
- $product = ProductClass::getById($productId, true);
- ProductClass::check($product, $this->mainId);
- $where = ['productId' => $productId];
- $respond = OrderItemClass::getOrderInfoList($where);
- util::success($respond);
- }
- //修改花材的备注 ssh 20240514
- public function actionUpdateItemRemark()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $remark = $get['remark'] ?? '';
- $info = OrderItemClass::getById($id, true);
- if (empty($info)) {
- util::fail('没有找到');
- }
- if ($info->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $info->remark = $remark;
- $info->save();
- $orderSn = $info->orderSn ?? '';
- $productId = $info->productId ?? 0;
- $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($order)) {
- util::fail('没有找订单');
- }
- $customId = $order->customId ?? 0;
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (!empty($bookSn) && !empty($remark)) {
- $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $productId], true);
- if (!empty($bookItemRes)) {
- $bookItemRes->hasRemark = 1;
- $bookItemRes->save();
- }
- $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
- if (!empty($bookCustomRes)) {
- $bookCustomRes->hasRemark = 1;
- $bookCustomRes->save();
- }
- $bookItemCustomRes = BookItemCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $productId], true);
- if (!empty($bookItemCustomRes)) {
- $bookItemCustomRes->hasRemark = 1;
- $bookItemCustomRes->remark = $remark;
- $bookItemCustomRes->save();
- }
- }
- util::complete();
- }
- //下载excel ssh 20241127
- public function actionGetDownExcel()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- $orderSn = $order->orderSn ?? '';
- $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- OrderItemClass::exportExcel($order, $list, $this->mainId);
- }
- }
|