| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- <?php
- namespace ghs\controllers;
- use biz\item\classes\PtItemClass;
- use biz\shop\classes\ShopClass;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\item\services\ItemService;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\miniUtil;
- use common\components\stringUtil;
- use common\components\util;
- use bizGhs\product\classes\ProductClass;
- use bizHd\wx\classes\WxOpenClass;
- use Yii;
- class ItemController extends BaseController
- {
- //检测是否要刷新
- public function actionCheckRefresh()
- {
- $mainId = $this->mainId;
- $staffId = $this->shopAdminId;
- $respond = Yii::$app->redis->executeCommand('GET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
- if ($respond == 'yes') {
- util::success(['remind' => 1]);
- }
- util::complete();
- }
- //批量恢复花材 ssh 20230206
- public function actionBatchRecover()
- {
- $post = Yii::$app->request->post();
- $string = $post['ids'] ?? '';
- $ids = json_decode($string, true);
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材');
- }
- $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
- if (empty($infoList)) {
- util::fail('请选择花材哦');
- }
- foreach ($infoList as $info) {
- if ($info->mainId != $this->mainId) {
- util::fail('请选择自己的花材');
- }
- $info->removeStatus = 0;
- $info->save();
- }
- util::complete('操作成功');
- }
- //批量删除花材 ssh 202302026
- public function actionBatchRemove()
- {
- $post = Yii::$app->request->post();
- $string = $post['ids'] ?? '';
- $ids = json_decode($string, true);
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材');
- }
- $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
- if (empty($infoList)) {
- util::fail('请选择花材哦');
- }
- foreach ($infoList as $info) {
- if ($info->mainId != $this->mainId) {
- util::fail('请选择自己的花材');
- }
- $name = $info->name ?? '';
- if ($info->delStatus != 1) {
- util::fail($name . ' 停用了才能删除');
- }
- $info->removeStatus = 1;
- $info->save();
- }
- util::complete('操作成功');
- }
- //批量启用花材 ssh 20230206
- public function actionBatchEnable()
- {
- $post = Yii::$app->request->post();
- $string = $post['ids'] ?? '';
- $ids = json_decode($string, true);
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材');
- }
- $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
- if (empty($infoList)) {
- util::fail('请选择花材哦');
- }
- foreach ($infoList as $info) {
- if ($info->mainId != $this->mainId) {
- util::fail('请选择自己的花材');
- }
- $info->delStatus = 0;
- $info->save();
- }
- util::complete('操作成功');
- }
- //批量停用花材 20230206
- public function actionBatchStop()
- {
- $post = Yii::$app->request->post();
- $string = $post['ids'] ?? '';
- $ids = json_decode($string, true);
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材');
- }
- $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
- if (empty($infoList)) {
- util::fail('请选择花材哦');
- }
- foreach ($infoList as $info) {
- if ($info->mainId != $this->mainId) {
- util::fail('请选择自己的花材');
- }
- $name = $info->name ?? '';
- if ($info->status != 2) {
- util::fail($name . ' 下载了才能停用');
- }
- $info->delStatus = 1;
- $info->save();
- }
- util::complete('操作成功');
- }
- //获取给散客下单的花材海报 ssh 20220111
- public function actionGetSkPoster()
- {
- $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;
- $lsShopId = $shop->lsShopId ?? 0;
- //scene不能超过32个字条
- $scene = "id=" . $id . '&a=' . $lsShopId;
- $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])) {
- $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';
- }
- $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);
- }
- //获取给花店下单的花材海报 ssh 20220111
- public function actionGetHdPoster()
- {
- $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::getWxInfo();
- $page = 'admin/ghsProduct/detail';
- $ptStyle = dict::getDict('ptStyle', 'hd');
- //小程序码,scene不能超过32个字条
- $scene = "id=" . $id . '&sId=' . $this->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', 'ghs');
- $prefix = imgUtil::getPrefix();
- $price = $item->price ?? 0;
- if ($item->discountPrice > 0) {
- $price = $item->discountPrice;
- }
- $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])) {
- $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';
- }
- $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);
- }
- //是否有C级价格大于B级的 ssh 20221204
- public function actionGetErrorPrice()
- {
- $shop = $this->shop;
- $list = ItemClass::errorPrice($shop);
- util::success(['list' => $list]);
- }
- //列出所有花材,包括特价花材列表 ssh 20220315
- public function actionShowList()
- {
- $where['mainId'] = $this->mainId;
- $where['delStatus'] = 0;
- $where['status'] = 1;
- $list = ItemClass::getShowList($where);
- $mainId = $this->mainId;
- $get = Yii::$app->request->get();
- $isCashier = $get['isCashier'] ?? 0;
- if ($isCashier == 1) {
- //去掉收银台提示价格更新
- $staffId = $this->shopAdminId;
- Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
- }
- util::success(['list' => $list]);
- }
- public function actionAdd()
- {
- util::fail('开发中');
- }
- //批量添加花材
- public function actionBatchAdd()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $post = Yii::$app->request->post();
- //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
- $data = $post['data'];
- if (empty($data)) {
- util::fail("请选花材");
- }
- $data = json_decode($data, true);
- if (is_array($data) == false || empty($data)) {
- util::fail("请选花材");
- }
- $shop = $this->shop;
- $shopId = $this->shopId;
- $mainId = $this->mainId;
- $sjId = $this->sjId;
- $adminId = $this->adminId;
- $ids = array_column($data, 'itemId');
- $ids = array_unique(array_filter($ids));
- $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
- if (!empty($has)) {
- $hasName = $has->name ?? '';
- util::fail($hasName . " 已经添加过了");
- }
- $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- foreach ($data as $v) {
- $ptItemId = $v['itemId'] ?? 0;
- $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
- $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
- $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
- $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
- $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
- $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
- $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
- $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
- $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
- $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
- $cover = $ptItemInfo[$ptItemId]['cover'] ?? 'default-img.png';
- $v['ratio'] = $ratio;
- $v['cover'] = $cover;
- $v['shelfLife'] = $shelfLife;
- $v['ratioType'] = $ratioType;
- $v['variety'] = $variety;
- $v['stockWarning'] = $stockWarning;
- $v['weight'] = $weight;
- $v['bigUnit'] = $bigUnit;
- $v['smallUnit'] = $smallUnit;
- $v['bigUnitId'] = $bigUnitId;
- $v['smallUnitId'] = $smallUnitId;
- $v['adminId'] = $adminId;
- $v['sjId'] = $sjId;
- $v['shopId'] = $shopId;
- $v['mainId'] = $mainId;
- $v['staffName'] = $shopAdmin->name ?? '';
- $name = $v['name'] ?? '';
- $price = is_numeric($v['price']) ? $v['price'] : 0;
- $skPrice = is_numeric($v['skPrice']) ? $v['skPrice'] : 0;
- $cost = is_numeric($v['cost']) ? $v['cost'] : 0;
- if ($price <= 0) {
- util::fail("请填写{$name}的花店价");
- }
- if ($skPrice <= 0) {
- util::fail("请填写{$name}的个人价");
- }
- if ($cost <= 0) {
- util::fail("请填写{$name}的成本价");
- }
- if ($price > $skPrice) {
- util::fail("{$name}的花店价比个人价还高");
- }
- if ($cost > $price) {
- util::fail("{$name}的成本价比花店价还高");
- }
- $skMore = bcsub($skPrice, $price, 2);
- $addPrice = bcsub($price, $cost, 2);
- $v['skMore'] = $skMore;
- $v['addPrice'] = $addPrice;
- ProductClass::addProduct($v, $shop);
- }
- $transaction->commit();
- util::complete('添加成功');
- } catch (Exception $e) {
- $transaction->rollBack();
- 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 20220820
- public function actionColorList()
- {
- $mainId = $this->mainId ?? 0;
- $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
- util::success(['list' => $list]);
- }
- //多颜色管理启用与停用 ssh 20221229
- public function actionChangeVariety()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $variety = $get['variety'] ?? 0;
- $info = ItemClass::getById($id, true);
- if (empty($info) || $info->mainId != $this->mainId) {
- util::fail('操作失败');
- }
- $info->variety = $variety;
- $info->save();
- util::complete('操作成功');
- }
- //拆散花材 ssh 20221229
- public function actionBreakItem()
- {
- util::fail('开发中');
- util::complete();
- }
- }
|