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' => '设置成功', ]); } }