| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- <?php
- namespace hd\controllers;
- use biz\item\classes\PtItemClass;
- use bizHd\item\classes\ItemClass;
- use bizGhs\pictext\classes\PicTextGhsItemClass;
- use bizHd\custom\classes\CustomClass;
- use bizHd\product\classes\ProductClass;
- use bizHd\wx\classes\WxOpenClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\miniUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class ItemController extends BaseController
- {
- //列出所有花材 ssh 20240222
- public function actionGetItemList()
- {
- $get = Yii::$app->request->get();
- $search = $get['search'] ?? '';
- $requestType = $get['requestType'] ?? 'kd';
- $classId = $get['classId'] ?? 0;
- $lookStock = $get['lookStock'] ?? 0;
- $where['mainId'] = $this->mainId;
- if ($requestType == 'kd') {
- $where['delStatus'] = 0;
- $where['status'] = 1;
- } elseif ($requestType == 'itemList') {
- $where['delStatus'] = 0;
- if ($lookStock == 1) {
- $where['stock>'] = 0;
- }
- if ($lookStock == 2) {
- $where['stock'] = 0;
- }
- unset($where['status']);
- } elseif ($requestType == 'changePrice') {
- $where['delStatus'] = 0;
- $where['stock>'] = 0;
- } elseif ($requestType == 'hasStockList') {
- $where['delStatus'] = 0;
- $where['stock>'] = 0;
- } elseif ($requestType == 'book') {
- $where['delStatus'] = 0;
- unset($where['status']);
- } elseif ($requestType == 'outList') {
- $where['delStatus'] = 0;
- $where['status'] = 2;
- $where['removeStatus'] = 0;
- } elseif ($requestType == 'stopList') {
- $where['delStatus'] = 1;
- unset($where['status']);
- $where['removeStatus'] = 0;
- } elseif ($requestType == 'removeList') {
- $where['delStatus'] = 1;
- unset($where['status']);
- $where['removeStatus'] = 1;
- } elseif ($requestType == 'cg') {
- $where['delStatus'] = 0;
- unset($where['status']);
- } elseif ($requestType == 'changeStock') {
- $where['delStatus'] = 0;
- unset($where['status']);
- } elseif ($requestType == 'check') {
- $where['delStatus'] = 0;
- unset($where['status']);
- } elseif ($requestType == 'stockOut') {
- $where['delStatus'] = 0;
- $where['status'] = 1;
- } elseif ($requestType == 'break') {
- $where['delStatus'] = 0;
- $where['status'] = 1;
- } elseif ($requestType == 'part') {
- $where['delStatus'] = 0;
- $where['status'] = 1;
- } else {
- util::fail('没有定义的请求方式');
- }
- if (!empty($search)) {
- if (stringUtil::isLetter($search)) {
- $search = strtolower($search);
- $where['py'] = ['like', $search];
- } else {
- $where['name'] = ['like', $search];
- }
- } else {
- if (!empty($classId)) {
- if ($classId == -1) {
- $where['discountPrice>'] = 0;
- } elseif ($classId == -2) {
- $where['reachNum>'] = 0;
- } elseif ($classId == -3) {
- $where['presell'] = 1;
- } else {
- $where['classId'] = $classId;
- }
- }
- }
- $customId = $get['customId'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (!empty($custom)) {
- if ($custom->shopId != $this->shopId) {
- util::fail('不是你的客户哦,编号55236');
- }
- }
- $level = 0;
- if($requestType == 'itemList'){
- //如果是花材列表页,则显示三个价格,其他地方,比如拆散和报损那些,只显示零售价
- $level = 1;
- }
- $field = '*';
- $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
- $list = $result['list'] ?? [];
- if ($requestType == 'kd') {
- $list = ProductClass::kdItemGroup($list, $level);
- } elseif ($requestType == 'itemList') {
- $list = ProductClass::itemListGroup($list, $level);
- } elseif ($requestType == 'changePrice') {
- $list = ProductClass::changePriceGroup($list, $level);
- } elseif ($requestType == 'break') {
- $list = ProductClass::breakItemGroup($list, $level);
- } elseif ($requestType == 'part') {
- $list = ProductClass::partItemGroup($list, $level);
- } elseif ($requestType == 'check') {
- $list = ProductClass::checkItemGroup($list, $level);
- } elseif ($requestType == 'cg') {
- $list = ProductClass::cgItemGroup($list, $level);
- } elseif ($requestType == 'changeStock') {
- $list = ProductClass::changeStockGroup($list, $level);
- } elseif ($requestType == 'stockOut') {
- $list = ProductClass::stockOutGroup($list, $level);
- } else {
- util::fail('没有数据');
- }
- $result['list'] = $list;
- util::success($result);
- }
- //增加和减少半扎 ssh 20250417
- public function actionChangeHalf()
- {
- util::fail('此功能已停用');
- $post = Yii::$app->request->post();
- $productId = $post['productId'] ?? '';
- $add = $post['add'] ?? 0;
- $remark = $post['remark'] ?? '';
- $product = ProductClass::getLockById($productId);
- if (empty($product)) {
- util::fail('没有找到花材');
- }
- if ($product->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- if ($product->ratioType == 1) {
- util::fail('若干扎的花材不能减半份');
- }
- //避免重复提交
- util::checkRepeatCommit($this->adminId, 4);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shop = $this->shop;
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $staffId = $staff->id;
- $adminId = $this->adminId;
- $params = [
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'adminId' => $adminId,
- 'remark' => $remark,
- ];
- ItemClass::modifyHalf($shop, $product, $params, $add);
- $product = ProductClass::getLockById($productId);
- $stock = $product->stock;
- $stock = floatval($stock);
- $transaction->commit();
- util::success(['stock' => $stock]);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("加减半份失败原因:" . $e->getMessage());
- util::fail('加减半份失败');
- }
- }
- //检测是否要刷新
- public function actionCheckRefresh()
- {
- $mainId = $this->mainId;
- $staffId = $this->shopAdminId;
- $respond = Yii::$app->redis->executeCommand('GET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
- if ($respond == 'yes') {
- util::success(['remind' => 1]);
- }
- util::complete();
- }
- //列出所有花材,包括特价花材列表 ssh 20220315
- public function actionShowList()
- {
- $headers = Yii::$app->getRequest()->getHeaders();
- $requestVersion = $headers->get('appVersion');
- $currentVersion = dict::getDict('appVersion');
- if ($requestVersion < $currentVersion) {
- util::fail('请先升级系统');
- }
- $get = Yii::$app->request->get();
- $isCashier = $get['isCashier'] ?? 0;
- $mainId = $this->mainId;
- if ($isCashier == 1) {
- //去掉收银台提示价格更新
- $staffId = $this->shopAdminId;
- Yii::$app->redis->executeCommand('DEL', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
- }
- $where['mainId'] = $mainId;
- $where['delStatus'] = 0;
- $where['status'] = 1;
- $list = \bizHd\item\classes\ItemClass::getShowList($where);
- $productList = [];
- if (!empty($list)) {
- foreach ($list as $key => $item) {
- if (!empty($item)) {
- $productList = array_merge($productList, $item);
- }
- }
- }
- util::success(['list' => $list, 'productList' => $productList]);
- }
- public function actionAdd()
- {
- util::fail('开发中');
- }
- public function actionBatchAdd()
- {
- util::fail('开发中');
- }
- public function actionDelete()
- {
- util::fail('不能删除哦!');
- }
- //获取平台里的花材信息
- public function actionPlatformItem()
- {
- $py = Yii::$app->request->get('py', '');
- $where = [];
- if ($py) {
- $where = ['py' => $py];
- }
- $list = PtItemClass::getItemList($where);
- util::success($list);
- }
- //获取给散客下单的花材海报 ssh 20220111
- public function actionGetPoster()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $item = ItemClass::getById($id, true);
- if (empty($item) || $item->mainId != $this->mainId) {
- util::fail('获取失败');
- }
- $cover = $item->cover ?? '';
- if (empty($cover)) {
- util::fail('获取失败');
- }
- $merchant = WxOpenClass::getMallWxInfo();
- $page = 'pages/item/detail';
- $ptStyle = dict::getDict('ptStyle', 'mall');
- $shop = $this->shop;
- $shopId = $shop->id ?? 0;
- //scene不能超过32个字条
- $scene = "id=" . $id . '&a=' . $shopId;
- $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
- $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
- $miniCodeBase64 = stringUtil::ossBase64($miniCode);
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
- $prefix = imgUtil::getPrefix();
- $price = $item->skPrice ?? 0;
- if ($item->discountPrice > 0) {
- $skMore = $item->skMore ?? 0;
- $price = bcadd($item->discountPrice, $skMore, 2);
- }
- $newPrice = '¥' . floatval($price);
- $priceBase64 = stringUtil::ossBase64($newPrice);
- $name = $item->name ?? '';
- $nameBase64 = stringUtil::ossBase64($name);
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $newStaffName = $staffName . ' 为您推荐';
- $staffNameBase64 = stringUtil::ossBase64($newStaffName);
- //花材主图
- $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
- $itemCoverBase64 = stringUtil::ossBase64($itemCover);
- $logoBase64 = '';
- if (in_array($this->mainId, [52, 1459, 13495])) {
- $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- if ($this->mainId == 1459) {
- $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- }
- if ($this->mainId == 13495) {
- $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- }
- $logoBase64 = stringUtil::ossBase64($logo);
- }
- $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
- //花材主图
- $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
- //小程序码
- $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
- if (!empty($logoBase64)) {
- //logo
- $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
- }
- //为你推荐
- $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
- //标题
- $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
- //价格
- $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
- $respond = ['imgUrl' => $url];
- util::success($respond);
- }
- //获取花材描述
- public function actionDesc()
- {
- $itemId = Yii::$app->request->get('itemId', 0);
- $picText = PicTextGhsItemClass::getByCondition(['mainId'=> $this->mainId, 'ghsItemId' => $itemId, 'delStatus' => 0], true);
- if (empty($picText)) {
- // 适配前端的返回处理 -- 本来要使用 util::fail()
- util::success('not_exist');
- }
- if ($picText->mainId != $this->mainId) {
- util::fail('没有找到描述');
- }
- util::success($picText);
- }
- //创建花材描述(花材介绍)
- public function actionCreateDesc()
- {
- $form = new \ghs\models\item\CreateDescForm(); // 暂时使用同一份 ghs,项目独立时,再复制一份
- $form->load(Yii::$app->request->post(), '');
- if (!$form->validateForm()) {
- return;
- }
- $data = $form->attributes;
- $exists = PicTextGhsItemClass::exists(['mainId'=>$this->mainId, 'ghsItemId' => $data['itemId'], 'delStatus' => 0]);
- if ($exists) {
- util::fail('该商品已存在图文内容,请勿重复添加');
- }
- $data['mainId'] = $this->mainId;
- $data['ghsItemId'] = $data['itemId'];
- $result = PicTextGhsItemClass::add($data);
- if ($result) {
- util::success($result);
- }
- util::fail('创建失败');
- }
- //更新花材描述(花材介绍)
- public function actionUpdateDesc()
- {
- $form = new \ghs\models\item\CreateDescForm();
- $form->load(Yii::$app->request->post(), '');
- if (!$form->validateForm()) {
- return;
- }
- $data = $form->attributes;
- $id = $data['id'];
- $info = PicTextGhsItemClass::getById($id, false, 'id');
- if (empty($info)) {
- util::fail('描述不存在');
- }
- $data['mainId'] = $this->mainId;
- $result = PicTextGhsItemClass::updateById($id, $data);
- if ($result) {
- util::success($result);
- }
- util::fail('更新失败');
- }
- public function actionChangeFrontHide()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $status = $get['status'] ?? '';
- if (is_numeric($status) == false) {
- util::fail('请选择方式');
- }
- $info = ItemClass::getById($id, true);
- if (empty($info)) {
- util::fail('没有找到花材');
- }
- if ($info->mainId != $this->mainId) {
- util::fail('不是你的花材呢');
- }
- $info->frontHide = $status;
- $info->save();
- util::complete();
- }
- }
|