You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
5.0 KiB
162 lines
5.0 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\controller\store\system;
|
|
|
|
|
|
use app\controller\store\AuthController;
|
|
use app\services\message\SystemPrinterServices;
|
|
use app\services\store\StoreConfigServices;
|
|
use think\facade\App;
|
|
|
|
|
|
/**
|
|
* Class SystemPrinter
|
|
* @package app\controller\store\system
|
|
*/
|
|
class SystemPrinter extends AuthController
|
|
{
|
|
|
|
/**
|
|
* SystemRole constructor.
|
|
* @param App $app
|
|
* @param SystemPrinterServices $services
|
|
*/
|
|
public function __construct(App $app, SystemPrinterServices $services)
|
|
{
|
|
parent::__construct($app);
|
|
$this->services = $services;
|
|
}
|
|
|
|
|
|
/**
|
|
* 显示管理员资源列表
|
|
* @return mixed
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
$where['type'] = 1;
|
|
$where['store_id'] = $this->storeId;
|
|
return app('json')->success($this->services->index($where));
|
|
}
|
|
|
|
/**
|
|
* 获取当前登陆门店管理员的信息
|
|
* @return mixed
|
|
*/
|
|
public function info($id)
|
|
{
|
|
return app('json')->success($this->services->getInfo((int)$id));
|
|
}
|
|
|
|
|
|
/**
|
|
* 保存管理员
|
|
* @return mixed
|
|
*/
|
|
public function save(StoreConfigServices $storeConfigServices, $id)
|
|
{
|
|
$data = $this->request->postMore([
|
|
['name', ''],//名称
|
|
['plat_type', 1],//打印机类型1易联云 2飞鹅云
|
|
['print_event', 1],//打印事件1:下单后2:支付后
|
|
['print_num', 1],//打印联数
|
|
['status', 1],//状态
|
|
['store_develop_id', 1],//易联云用户ID
|
|
['store_printing_api_key', 1],//易联云应用密钥
|
|
['store_printing_client_id', 1],//易联云应用ID
|
|
['store_terminal_number', 1],//易联云终端号
|
|
|
|
['store_fey_user', 1],//飞鹅云USER
|
|
['store_fey_ukey', 1],//飞鹅云UYEK
|
|
['store_fey_sn', 1],//飞鹅云SN
|
|
]);
|
|
if (!$data['name']) {
|
|
return app('json')->fail('请输入打印机名称');
|
|
}
|
|
if ((int)$data['print_num'] > 9 || (int)$data['print_num'] < 1) {
|
|
return app('json')->fail('打印联数为1-9数字');
|
|
}
|
|
$one = $this->services->getOne(['name' => $data['name'], 'type' => 1, 'relation_id' => $this->storeId]);
|
|
if ($one && (($id && $one['id'] != $id) || !$id)) {
|
|
return app('json')->fail('打印机名称重复');
|
|
}
|
|
if ($data['plat_type'] == 1) {//易联云
|
|
if (!$data['store_develop_id'] || !$data['store_printing_api_key'] || !$data['store_printing_client_id'] || !$data['store_terminal_number']) {
|
|
return app('json')->fail('请完善易联云打印机配置');
|
|
}
|
|
} else {
|
|
if (!$data['store_fey_user'] || !$data['store_fey_ukey'] || !$data['store_fey_sn']) {
|
|
return app('json')->fail('请完善飞蛾云打印机配置');
|
|
}
|
|
}
|
|
$data['type'] = 1;
|
|
$data['relation_id'] = $this->storeId;
|
|
$default = $this->services->default;
|
|
$configData = array_merge($default, array_intersect_key($data, $default));
|
|
unset($data['store_print_type'],
|
|
$data['store_terminal_number'],
|
|
$data['store_printing_client_id'],
|
|
$data['store_printing_api_key'],
|
|
$data['store_develop_id'],
|
|
$data['store_fey_user'],
|
|
$data['store_fey_ukey'],
|
|
$data['store_fey_sn']);
|
|
if ($id) {//修改
|
|
$res = $this->services->update($id, $data);
|
|
} else {
|
|
$data['add_time'] = time();
|
|
$res = $this->services->save($data);
|
|
$id = $res->id;
|
|
}
|
|
$storeConfigServices->saveConfig($configData, 1, $this->storeId, (int)$id);
|
|
\crmeb\services\SystemConfigService::clear();
|
|
if ($res) {
|
|
return app('json')->success('保存成功');
|
|
} else {
|
|
return app('json')->fail('保存失败');
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 删除打印机
|
|
* @param $id
|
|
* @return mixed
|
|
*/
|
|
public function delete($id)
|
|
{
|
|
if (!$id) return $this->fail('删除失败,缺少参数');
|
|
/** @var StoreConfigServices $service */
|
|
$services = app()->make(StoreConfigServices::class);
|
|
//删除打印机 参数配置
|
|
$services->delete(['print_id' => $id]);
|
|
//删除打印机
|
|
$this->services->delete($id);
|
|
\crmeb\services\SystemConfigService::clear();
|
|
return app('json')->success('删除成功!');
|
|
}
|
|
|
|
/**
|
|
* 修改状态
|
|
* @param $id
|
|
* @param $status
|
|
* @return mixed
|
|
*/
|
|
public function set_status($id, $status)
|
|
{
|
|
$this->services->update((int)$id, ['status' => $status]);
|
|
return app('json')->success($status == 0 ? '关闭成功' : '开启成功');
|
|
}
|
|
|
|
}
|
|
|