| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?php
- namespace ghs\controllers;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\live\classes\LiveOrderClass;
- use bizGhs\live\classes\LiveOrderCustomClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\dateUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class LiveOrderController extends BaseController
- {
- //获取未转化的花材 ssh 20241009
- public function actionUnConvert()
- {
- $mainId = $this->mainId;
- $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId, 'switchOrder' => 0], null, '*', 'itemId', true);
- util::success(['list'=>$list]);
- }
- //转换成订单 ssh 20241006
- public function actionConvertOrder()
- {
- $mainId = $this->mainId;
- $cacheKey = 'live_order_' . $mainId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('已经在转换了');
- }
- $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId, 'switchOrder' => 0], null, '*', null, true);
- if (empty($list)) {
- util::fail('没有记录需要转换');
- }
- $arr = [];
- foreach ($list as $live) {
- $addTime = $live->addTime;
- $date = date("Y-m-d", strtotime($addTime));
- $arr[$date] = 1;
- }
- if (count($arr) > 1) {
- util::fail('有记录不是同一天的');
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 180, 1]);
- util::success('提交成功,3分钟后查看订单');
- }
- //走播单列表 ssh 20241003
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $staffId = $get['staffId'] ?? 0;
- $switchOrder = $get['switchOrder'] ?? -1;
- $searchContent = $get['searchContent'] ?? '';
- $where = [];
- $where['mainId'] = $this->mainId;
- if (!empty($staffId)) {
- $where['staffId'] = $staffId;
- }
- if (!empty($searchContent)) {
- if (stringUtil::isLetter($searchContent)) {
- $where['itemPy'] = ['like', $searchContent];
- } else {
- $where['itemName'] = ['like', $searchContent];
- }
- }
- if ($switchOrder > -1) {
- $where['switchOrder'] = $switchOrder;
- }
- $searchTime = $get['searchTime'] ?? '';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $respond = LiveOrderClass::getOrderList($where);
- util::success($respond);
- }
- //添加订单 ssh 20241003
- public function actionAddOrder()
- {
- $post = Yii::$app->request->post();
- $itemId = $post['itemId'] ?? 0;
- if (empty($itemId)) {
- util::fail('请选花材');
- }
- $product = ProductClass::getById($itemId, true);
- if (empty($product)) {
- util::fail('没有找到花材');
- }
- if ($product->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $itemPrice = $post['itemPrice'] ?? 0;
- $itemRemark = $post['itemRemark'] ?? '';
- $selectCustom = $post['selectCustom'] ?? '';
- if (empty($selectCustom)) {
- util::fail('没有客户');
- }
- $arr = json_decode($selectCustom, true);
- if (empty($arr) || is_array($arr) == false) {
- util::fail('没有客户信息');
- }
- $mainId = $this->mainId;
- $hasItem = LiveOrderClass::getByCondition(['mainId' => $mainId, 'itemId' => $itemId, 'switchOrder' => 0], true);
- if (!empty($hasItem)) {
- util::fail('这个花材已添加过');
- }
- $has = [];
- $customList = [];
- foreach ($arr as $key => $info) {
- $customId = $info['customId'] ?? 0;
- if (isset($has[$customId])) {
- util::fail('重复的客户');
- }
- $has[$customId] = 1;
- $customName = $info['customName'] ?? '';
- $num = $info['num'] ?? 0;
- $price = $info['price'] ?? 0;
- $customList[] = ['customId' => $customId, 'customName' => $customName, 'num' => $num, 'price' => $price];
- }
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['product' => $product, 'customList' => $customList, 'staffId' => $staffId, 'staffName' => $staffName, 'itemPrice' => $itemPrice, 'itemRemark' => $itemRemark];
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- LiveOrderClass::addOrder($params, $mainId);
- $transaction->commit();
- util::complete('创建成功');
- } catch (\Exception $e) {
- Yii::info("操作失败原因:" . $e->getMessage());
- $transaction->rollBack();
- util::fail('操作失败');
- }
- }
- //获取明细 ssh 20241005
- public function actionGetDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $live = LiveOrderClass::getById($id, true);
- if (empty($live)) {
- util::fail('没有找到记录');
- }
- if ($live->mainId != $this->mainId) {
- util::fail('不是你的记录');
- }
- $orderSn = $live->orderSn ?? '';
- $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- util::success(['customList' => $customList, 'info' => $live]);
- }
- //添加客户 ssh 20241005
- public function actionAddCustom()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $customId = $post['customId'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是你的客户');
- }
- $num = $post['num'] ?? 0;
- $price = $post['price'] ?? 0;
- $live = LiveOrderClass::getById($id, true);
- if (empty($live)) {
- util::fail('没有找到记录');
- }
- if ($live->mainId != $this->mainId) {
- util::fail('不是你的记录');
- }
- if ($live->switchOrder == 1) {
- util::fail('已转订单,不能添加');
- }
- $params = ['num' => $num, 'price' => $price];
- LiveOrderClass::addCustom($params, $custom, $live);
- util::complete('添加成功');
- }
- //删除客户 ssh 20241005
- public function actionDelCustom()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $customId = $get['customId'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是你的客户');
- }
- $live = LiveOrderClass::getById($id, true);
- if (empty($live)) {
- util::fail('没有找到记录');
- }
- if ($live->mainId != $this->mainId) {
- util::fail('不是你的记录');
- }
- if ($live->switchOrder == 1) {
- util::fail('已转订单,不能删除');
- }
- LiveOrderClass::delCustom($custom, $live);
- util::complete('添加成功');
- }
- //更新客户 ssh 20241005
- public function actionUpdateCustom()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $customList = $post['customList'] ?? 0;
- $customData = json_decode($customList, true);
- if (empty($customData)) {
- util::fail('没有客户信息');
- }
- $live = LiveOrderClass::getById($id, true);
- if (empty($live)) {
- util::fail('没有找到记录');
- }
- if ($live->mainId != $this->mainId) {
- util::fail('不是你的记录');
- }
- if ($live->switchOrder == 1) {
- util::fail('已转订单,不能修改');
- }
- LiveOrderClass::updateCustom($customData, $live);
- util::complete('修改成功');
- }
- public function actionPrintOrder()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $live = LiveOrderClass::getById($id, true);
- if (empty($live)) {
- util::fail('没有找到');
- }
- if ($live->mainId != $this->mainId) {
- util::fail('不是你的');
- }
- $orderSn = $live->orderSn ?? '';
- $liveCustomList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (empty($liveCustomList)) {
- util::fail('没有客户预订');
- }
- $ids = array_column($liveCustomList, 'customId');
- $customList = CustomClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
- $table = [];
- foreach ($liveCustomList as $liveCustom) {
- $customId = $liveCustom['customId'] ?? 0;
- $currentName = $liveCustom['customName'] ?? '';
- $num = $liveCustom['num'] ?? '';
- $customInfo = $customList[$customId] ?? [];
- if (isset($customInfo['seatSnName']) && !empty($customInfo['seatSnName'])) {
- $currentName = $customInfo['seatSnName'];
- }
- $seatSn = $customInfo['seatSn'] ?? '';
- $table[] = [
- 'name' => $currentName,
- 'num' => $num,
- 'seatSn' => $seatSn,
- 'remark' => '',
- ];
- }
- $addTime = $live->addTime;
- $itemName = $live->itemName ?? '';
- $time = date("Y-m-d", strtotime($addTime));
- $itemPrice = $live->itemPrice ? floatval($live->itemPrice) : 0;
- $itemRemark = $live->itemRemark ?? '';
- $title = $time . ' ' . $itemName . ' ' . $itemPrice . '元';
- if (!empty($itemRemark)) {
- $title .= ' ' . $itemRemark;
- }
- $a4Print = [
- 'table' => $table,
- 'title' => $title,
- ];
- $info['printData'] = $a4Print;
- $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":16,"lineHeight":30,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":107.90432245461145,"title":"货位","field":"seatSn","checked":true,"columnId":"seatSn","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":186.15171514242957,"title":"客户名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":103.10001880877743,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":140.84394359418155,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":93.32065807548679,"title":"日期","field":"shortTime","checked":false,"columnId":"shortTime","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.09275968851016,"title":"库存","field":"stock","checked":false,"columnId":"stock","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":276,"title":"金额\n","field":"amount","checked":false,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":67.5,"top":18,"height":35,"width":455,"title":"文本","right":522.5,"bottom":53,"vCenter":295,"hCenter":35.5,"field":"title","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":19.5,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":819,"paperNumberContinue":true,"watermarkOptions":{"content":"","rotate":25,"timestamp":true,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
- $info['template'] = $template;
- $live->printOrder = 1;
- $live->save();
- util::success($info);
- }
- //修改创建时间 ssh 20241006
- public function actionChangeDate()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $live = LiveOrderClass::getById($id, true);
- if (empty($live)) {
- util::fail('没有找到');
- }
- if ($live->mainId != $this->mainId) {
- util::fail('不是你的');
- }
- $flag = $get['flag'] ?? 0;
- $addTime = $live->addTime;
- if ($flag == 0) {
- $time = strtotime($addTime) - 86400;
- } else {
- $time = strtotime($addTime) + 86400;
- }
- $newDate = date("Y-m-d H:i:s", $time);
- $live->addTime = $newDate;
- $live->save();
- util::complete('修改成功');
- }
- }
|