| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers\setting;
- use app\models\Option;
- use app\models\Printer;
- use app\models\PrinterSetting;
- use app\modules\admin\controllers\BaseController;
- use app\modules\admin\models\PrinterForm;
- use app\utils\DqznPrint;
- use app\utils\XhyPrint;
- use yii\helpers\Json;
- class PrinterController extends BaseController
- {
- /**
- * 获取云打印列表
- * @return \yii\web\Response
- */
- public function actionList()
- {
- $query = Printer::find()
- ->where(['is_delete' => 0]);
- if (get_supplier_id()) {
- $query->andWhere(['supplier_id' => get_supplier_id(), 'type' => 1]);
- $setting = PrinterSetting::findOne(['supplier_id' => get_supplier_id()]);
- } else if(get_mch_id()) {
- $query->andWhere(['mch_id' => get_mch_id()]);
- $setting = PrinterSetting::findOne(['mch_id' => get_mch_id()]);
- } else {
- $query->andWhere(['store_id' => get_store_id(), 'md_id' => get_md_id()]);
- $setting = PrinterSetting::findOne(['store_id' => get_store_id(), 'md_id' => get_md_id()]);
- }
- $setting['printer_id'] = array_map('intval',explode(',',$setting['printer_id']));
- $list = $query->orderBy(['id' => SORT_DESC])->all();
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $list,
- 'setting' => $setting
- ]
- ]);
- }
- /**
- * 获取详情
- */
- public function actionEdit($id = null)
- {
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'model' => Printer::findOne($id)
- ]
- ]);
- }
- /**
- * 保存
- */
- public function actionSave()
- {
- $arr = [];
- if(get_mch_id()){
- $arr['mch'] = 1;
- $arr['mch_id'] = get_mch_id();
- }
- $form = new PrinterForm();
- $form->attributes = post_params();
- return $this->asJson($form->save($arr));
- }
- /**
- * 删除
- * @param $id
- * @return \yii\web\Response
- */
- public function actionDel($id)
- {
- $model = Printer::findOne($id);
- if (empty($model)) {
- $res = ['code' => 1, 'msg' => '参数错误'];
- } else {
- try {
- // 删除芯烨云打印机
- if ($model->printer_type == 'xhy') {
- $setting = json_decode($model->printer_setting, true);
- (new XhyPrint($model->id))->delete_printer($setting['sn']);
- } elseif ($model->printer_type == 'dqzn') {
- $setting = json_decode($model->printer_setting, true);
- (new DqznPrint($model->id))->delete_printer($setting['sn']);
- }
- $model->is_delete = 1;
- if (!$model->save()) {
- throw new \Exception('删除失败');
- }
- $res = ['code' => 0, 'msg' => '删除成功'];
- } catch (\Exception $e) {
- $res = ['code' => 1, 'msg' => $e->getMessage()];
- }
- }
- return $this->asJson($res);
- }
- public function actionSaveSetting()
- {
- if (get_supplier_id()) {
- $model = PrinterSetting::findOne(['supplier_id' => get_supplier_id()]);
- } else if(get_mch_id()) {
- $model = PrinterSetting::findOne(['mch_id' => get_mch_id()]);
- } else {
- $model = PrinterSetting::findOne(['store_id' => get_store_id(), 'md_id' => get_md_id()]);
- }
- $model = $model ?: new PrinterSetting();
- if (get_supplier_id()) {
- $model->supplier_id = get_supplier_id();
- } else if(get_mch_id()) {
- $model->mch_id = get_mch_id();
- } else {
- $model->store_id = get_store_id();
- $model->md_id = get_md_id();
- }
- $model->printer_id = implode(',',post_params('printer_id'));
- $model->is_attr = post_params('is_attr');
- $model->big = post_params('big');
- $model->type = Json::encode(post_params('type', []));
- $res = $model->save() ? ['code' => 0, 'msg' => '保存成功'] : ['code' => 1, 'msg' => '保存失败'];
- return $this->asJson($res);
- }
- /**
- * 获取订单打印配置信息
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2022/12/28 17:48
- */
- public function actionGetPrintOrderSetting(){
- $result = Option::getPrintOrderSetting();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $result
- ]);
- }
- /**
- * 设置订单打印参数
- * @return \yii\web\Response
- * @throws \yii\db\Exception
- * User: hankaige
- * DATE TIME: 2022/12/28 17:52
- */
- public function actionSetPrintOrderSetting(){
- $store_id = get_store_id();
- $note_show = post_params('note_show',0);
- $note = post_params('note','');
- $qrcode_show = post_params('qrcode_show',0);
- $pay_notice = post_params('pay_notice',0);
- $not_pay_notice = post_params('not_pay_notice',0);
- Option::set('note_show', $note_show, $store_id, 'store');
- Option::set('note', $note, $store_id, 'store');
- Option::set('qrcode_show', $qrcode_show, $store_id, 'store');
- Option::set('pay_notice', $pay_notice, $store_id, 'store');
- Option::set('not_pay_notice', $not_pay_notice, $store_id, 'store');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '设置成功',
- ]);
- }
- }
|