@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\job;
|
||||
|
||||
use addons\shopro\library\traits\ActivityCache;
|
||||
use addons\shopro\library\traits\Groupon;
|
||||
use addons\shopro\library\traits\StockSale;
|
||||
use addons\shopro\model\Config;
|
||||
use addons\shopro\model\GoodsComment;
|
||||
use addons\shopro\model\Order;
|
||||
use addons\shopro\model\OrderAction;
|
||||
use addons\shopro\model\OrderItem;
|
||||
use think\queue\Job;
|
||||
|
||||
/**
|
||||
* 订单支付完成
|
||||
*/
|
||||
class OrderPayed extends BaseJob
|
||||
{
|
||||
use StockSale, ActivityCache, Groupon;
|
||||
|
||||
/**
|
||||
* 订单支付完成
|
||||
*/
|
||||
public function payed(Job $job, $data)
|
||||
{
|
||||
try {
|
||||
$order = $data['order'];
|
||||
$user = $data['user'];
|
||||
$order = Order::with('item')->where('id', $order['id'])->find();
|
||||
|
||||
// 数据库删订单的问题常见,这里被删的订单直接把队列移除
|
||||
if ($order) {
|
||||
\think\Db::transaction(function () use ($order, $user, $data) {
|
||||
// 订单减库存
|
||||
$this->realForwardStockSale($order);
|
||||
|
||||
// 判断,如果是拼团 真实加入团
|
||||
if (strpos($order['activity_type'], 'groupon') !== false) {
|
||||
$this->joinGroupon($order, $user);
|
||||
}
|
||||
|
||||
// 处理发票审核
|
||||
if ($order->invoice_status == 1) {
|
||||
$invoice = \addons\shopro\model\OrderInvoice::get(['order_id' => $order->id]);
|
||||
if ($invoice) {
|
||||
$invoice->status = 0;
|
||||
$invoice->save();
|
||||
}
|
||||
}
|
||||
// 处理消费返积分 TODO: 待测试
|
||||
$scoreConfig = Config::where('name', 'score')->find();
|
||||
$scoreConfig = json_decode($scoreConfig['value'], true);
|
||||
if (!empty($scoreConfig['consume_get_score']) && !empty($scoreConfig['consume_get_score_ratio'])) {
|
||||
$scoreRatio = intval($scoreConfig['consume_get_score_ratio']);
|
||||
$score = intval($scoreRatio * 0.01 * $order->total_fee);
|
||||
if ($score > 0) {
|
||||
\addons\shopro\model\User::score($score, $user['id'], 'consume_get_score', $order['id']);
|
||||
}
|
||||
}
|
||||
|
||||
// 检测有没有自动发货的商品,有就自动发货
|
||||
$order->checkDispatchAndSend($order, ['user' => $user]);
|
||||
});
|
||||
|
||||
// 支付成功的外部副作用必须在事务提交后触发,避免数据库回滚时已经打印小票。
|
||||
\think\Hook::listen('order_payed_after', ['order' => $order]);
|
||||
}
|
||||
|
||||
// 删除 job
|
||||
$job->delete();
|
||||
} catch (\Exception $e) {
|
||||
// 队列执行失败
|
||||
$error = json_encode([
|
||||
'a' => $e->getLine(),
|
||||
'b' => $e->getFile(),
|
||||
'c' => $e->getTrace(),
|
||||
'd' => $e->getMessage()
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
|
||||
\think\Log::error('queue-' . get_class() . '-payed' . ':执行失败,错误信息:' . $error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\job;
|
||||
|
||||
use addons\shopro\model\Order;
|
||||
use app\common\library\PrinterService;
|
||||
use think\Db;
|
||||
use think\queue\Job;
|
||||
|
||||
class OrderPrint extends BaseJob
|
||||
{
|
||||
public function handle(Job $job, $data)
|
||||
{
|
||||
$orderId = isset($data['order_id']) ? (int)$data['order_id'] : 0;
|
||||
$task = $orderId ? Db::name('shopro_order_print_task')->where('order_id', $orderId)->find() : null;
|
||||
|
||||
if (!$task || in_array((int)$task['status'], [1, 3], true)) {
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$order = Order::with('item')->where('id', $orderId)->find();
|
||||
if (!$order) {
|
||||
throw new \RuntimeException('订单不存在');
|
||||
}
|
||||
|
||||
Db::name('shopro_order_print_task')->where('id', $task['id'])->update([
|
||||
'status' => 2,
|
||||
'attempts' => (int)$task['attempts'] + 1,
|
||||
'updated_at' => time(),
|
||||
'last_error' => '',
|
||||
]);
|
||||
|
||||
$manualPrintKey = isset($task['manual_print_key']) ? $task['manual_print_key'] : '';
|
||||
$result = (new PrinterService())->printOrder($this->buildOrderData($order, $manualPrintKey));
|
||||
if (empty($result['accepted'])) {
|
||||
$this->failTask($task['id'], !empty($result['error']) ? $result['error'] : '云打印未受理', $result);
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
Db::name('shopro_order_print_task')->where('id', $task['id'])->update([
|
||||
// 云端已接单,仍需查询 queryOrderState 确认物理打印完成。
|
||||
'status' => 3,
|
||||
'cloud_order_id' => $result['cloud_order_id'],
|
||||
'printer_response' => $result['response'],
|
||||
'updated_at' => time(),
|
||||
'last_error' => '',
|
||||
]);
|
||||
\think\Queue::later(30, '\\addons\\shopro\\job\\OrderPrintStatus@handle', ['task_id' => $task['id']], 'shopro-high');
|
||||
$job->delete();
|
||||
} catch (\Exception $e) {
|
||||
if ($task) {
|
||||
$this->failTask($task['id'], $e->getMessage(), []);
|
||||
}
|
||||
\think\Log::error('订单小票打印失败,订单ID ' . $orderId . ': ' . $e->getMessage());
|
||||
$job->delete();
|
||||
}
|
||||
}
|
||||
|
||||
protected function buildOrderData($order, $manualPrintKey = '')
|
||||
{
|
||||
$items = [];
|
||||
foreach ((array)$order['item'] as $item) {
|
||||
$items[] = [
|
||||
'name' => (isset($item['goods_title']) ? $item['goods_title'] : '商品') . (!empty($item['goods_sku_text']) ? ' (' . $item['goods_sku_text'] . ')' : ''),
|
||||
'num' => isset($item['goods_num']) ? $item['goods_num'] : 1,
|
||||
'price' => isset($item['goods_price']) ? $item['goods_price'] : '0.00',
|
||||
];
|
||||
}
|
||||
|
||||
$address = (isset($order['province_name']) ? $order['province_name'] : '')
|
||||
. (isset($order['city_name']) ? $order['city_name'] : '')
|
||||
. (isset($order['area_name']) ? $order['area_name'] : '')
|
||||
. (isset($order['address']) ? $order['address'] : '');
|
||||
|
||||
return [
|
||||
'order_sn' => $order['order_sn'],
|
||||
'createtime' => $order['createtime'],
|
||||
'consignee' => isset($order['consignee']) ? $order['consignee'] : '客户',
|
||||
'phone' => isset($order['phone']) ? $order['phone'] : '',
|
||||
'address' => $address ?: '到店自提/商家配送',
|
||||
'total_fee' => isset($order['pay_fee']) ? sprintf('%.2f', $order['pay_fee']) : $order['total_fee'],
|
||||
'items' => $items,
|
||||
'print_idempotent' => $manualPrintKey ?: 'shopro-' . $order['id'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function failTask($taskId, $error, $result)
|
||||
{
|
||||
Db::name('shopro_order_print_task')->where('id', $taskId)->update([
|
||||
'status' => -1,
|
||||
'printer_response' => isset($result['response']) ? $result['response'] : '',
|
||||
'last_error' => mb_substr($error, 0, 500, 'UTF-8'),
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\Email;
|
||||
use app\common\library\PrinterService;
|
||||
use app\admin\model\shopro\Config as ConfigModel;
|
||||
use think\Exception;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* Shopro配置
|
||||
*
|
||||
* @icon fa fa-cogs
|
||||
* @remark 可以在此增改商城的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除
|
||||
*/
|
||||
class Config extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\shopro\Config
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $noNeedRight = ['check', 'rulelist'];
|
||||
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('app\admin\model\shopro\Config');
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$siteList = [];
|
||||
$groupList = ConfigModel::getGroupList();
|
||||
foreach ($groupList as $k => $v) {
|
||||
$siteList[$k]['name'] = $k;
|
||||
$siteList[$k]['title'] = $v;
|
||||
$siteList[$k]['list'] = [];
|
||||
}
|
||||
|
||||
foreach ($this->model->all() as $k => $v) {
|
||||
if (!isset($siteList[$v['group']])) {
|
||||
continue;
|
||||
}
|
||||
$value = $v->toArray();
|
||||
$value['title'] = __($value['title']);
|
||||
if (in_array($value['type'], ['select', 'selects', 'checkbox', 'radio'])) {
|
||||
$value['value'] = explode(',', $value['value']);
|
||||
}
|
||||
$value['content'] = json_decode($value['content'], true);
|
||||
$value['tip'] = htmlspecialchars($value['tip']);
|
||||
$siteList[$v['group']]['list'][] = $value;
|
||||
}
|
||||
$index = 0;
|
||||
foreach ($siteList as $k => &$v) {
|
||||
$v['active'] = !$index ? true : false;
|
||||
$index++;
|
||||
}
|
||||
$this->view->assign('siteList', $siteList);
|
||||
$this->view->assign('typeList', ConfigModel::getTypeList());
|
||||
$this->view->assign('ruleList', ConfigModel::getRegexList());
|
||||
$this->view->assign('groupList', ConfigModel::getGroupList());
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a", [], 'trim');
|
||||
if ($params) {
|
||||
foreach ($params as $k => &$v) {
|
||||
$v = is_array($v) ? implode(',', $v) : $v;
|
||||
}
|
||||
try {
|
||||
if (in_array($params['type'], ['select', 'selects', 'checkbox', 'radio', 'array'])) {
|
||||
$params['content'] = json_encode(ConfigModel::decode($params['content']), JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$params['content'] = '';
|
||||
}
|
||||
$result = $this->model->create($params);
|
||||
if ($result !== false) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($this->model->getError());
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param null $ids
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
if ($row) {
|
||||
$configList = [];
|
||||
foreach ($this->model->all() as $v) {
|
||||
if (isset($row[$v['name']])) {
|
||||
$value = $row[$v['name']];
|
||||
if (is_array($value) && isset($value['field'])) {
|
||||
$value = json_encode(ConfigModel::getArrayData($value), JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$value = is_array($value) ? implode(',', $value) : $value;
|
||||
}
|
||||
$v['value'] = $value;
|
||||
$configList[] = $v->toArray();
|
||||
}
|
||||
}
|
||||
$this->model->allowField(true)->saveAll($configList);
|
||||
try {
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
}
|
||||
|
||||
public function platform($type)
|
||||
{
|
||||
$action = $this->request->request('action', '');
|
||||
if ($type === 'printer' && $action === 'status') {
|
||||
return $this->printerStatus();
|
||||
}
|
||||
if ($type === 'printer' && $action === 'test') {
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error('测试打印仅支持 POST 请求');
|
||||
}
|
||||
return $this->printerTest();
|
||||
}
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post("data");
|
||||
if ($data) {
|
||||
try {
|
||||
$config = $this->model->get(['name' => $type]);
|
||||
if(!$config) {
|
||||
$this->model->allowField(true)->save([
|
||||
'name' => $type,
|
||||
'title' => $this->request->post("title"),
|
||||
'group' => $this->request->post("group"),
|
||||
'type' => 'array',
|
||||
'value' => $data,
|
||||
]);
|
||||
}else {
|
||||
$config->value = $data;
|
||||
$config->save();
|
||||
}
|
||||
|
||||
if ($type == 'chat') {
|
||||
// 存为文件
|
||||
file_put_contents(
|
||||
ROOT_PATH . 'addons' . DS . 'shopro' . DS . 'library' . DS . 'chat' . DS . 'config.php',
|
||||
'<?php' . "\n\nreturn " . var_export(json_decode($data, true), true) . ";"
|
||||
);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$config = $this->model->where(['name' => $type])->value('value');
|
||||
$config = json_decode($config, true);
|
||||
if ($type === 'wxOfficialAccount') {
|
||||
//动态解析微信公众号服务端Api Url地址域名
|
||||
$config['url'] = request()->domain() . '/addons/shopro/wechat';
|
||||
|
||||
}
|
||||
if($type === 'user') {
|
||||
$this->assignconfig('groupList', \app\admin\model\UserGroup::field('id,name,status')->select());
|
||||
}
|
||||
$this->assignconfig('row', $config);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
protected function printerStatus()
|
||||
{
|
||||
$result = (new PrinterService())->queryStatus();
|
||||
$online = !empty($result['accepted']) && (int)$result['data'] === 1;
|
||||
$message = $online ? '打印机在线' : (!empty($result['error']) ? $result['error'] : '打印机离线');
|
||||
|
||||
$this->success($message, '', [
|
||||
'online' => $online,
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function printerTest()
|
||||
{
|
||||
$timestamp = time();
|
||||
$result = (new PrinterService())->printOrder([
|
||||
'order_sn' => 'TEST-' . date('YmdHis', $timestamp),
|
||||
'createtime' => $timestamp,
|
||||
'consignee' => '系统测试',
|
||||
'phone' => '',
|
||||
'address' => '后台小票打印测试,请忽略',
|
||||
'total_fee' => '0.00',
|
||||
'items' => [[
|
||||
'name' => '测试小票(请忽略)',
|
||||
'num' => 1,
|
||||
'price' => '0.00',
|
||||
]],
|
||||
'print_idempotent' => 'shopro-admin-test-' . $timestamp . '-' . mt_rand(1000, 9999),
|
||||
], 1);
|
||||
|
||||
if (empty($result['accepted'])) {
|
||||
$this->error(!empty($result['error']) ? $result['error'] : '测试小票未被芯烨云受理');
|
||||
}
|
||||
|
||||
$printed = false;
|
||||
$cloudOrderId = $result['cloud_order_id'];
|
||||
for ($attempt = 0; $attempt < 3; $attempt++) {
|
||||
$state = (new PrinterService())->queryOrderState($cloudOrderId);
|
||||
if (!empty($state['printed'])) {
|
||||
$printed = true;
|
||||
break;
|
||||
}
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
$message = $printed ? '测试小票已打印' : '测试小票已送达芯烨云,等待打印机完成';
|
||||
$this->success($message, '', [
|
||||
'printed' => $printed,
|
||||
'cloud_order_id' => $cloudOrderId,
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param string $ids
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
$name = $this->request->post('name');
|
||||
$config = ConfigModel::getByName($name);
|
||||
if ($name && $config) {
|
||||
try {
|
||||
$config->delete();
|
||||
$this->refreshFile();
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新配置文件
|
||||
*/
|
||||
protected function refreshFile()
|
||||
{
|
||||
$config = [];
|
||||
foreach ($this->model->all() as $k => $v) {
|
||||
$value = $v->toArray();
|
||||
if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) {
|
||||
$value['value'] = explode(',', $value['value']);
|
||||
}
|
||||
if ($value['type'] == 'array') {
|
||||
$value['value'] = (array)json_decode($value['value'], true);
|
||||
}
|
||||
$config[$value['name']] = $value['value'];
|
||||
}
|
||||
file_put_contents(
|
||||
APP_PATH . 'extra' . DS . 'site.php',
|
||||
'<?php' . "\n\nreturn " . var_export($config, true) . ";"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测配置项是否存在
|
||||
* @internal
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
$config = $this->model->get($params);
|
||||
if (!$config) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error(__('Name already exist'));
|
||||
}
|
||||
} else {
|
||||
return $this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则列表
|
||||
* @internal
|
||||
*/
|
||||
public function rulelist()
|
||||
{
|
||||
//主键
|
||||
$primarykey = $this->request->request("keyField");
|
||||
//主键值
|
||||
$keyValue = $this->request->request("keyValue", "");
|
||||
|
||||
$keyValueArr = array_filter(explode(',', $keyValue));
|
||||
$regexList = \app\common\model\Config::getRegexList();
|
||||
$list = [];
|
||||
foreach ($regexList as $k => $v) {
|
||||
if ($keyValueArr) {
|
||||
if (in_array($k, $keyValueArr)) {
|
||||
$list[] = ['id' => $k, 'name' => $v];
|
||||
}
|
||||
} else {
|
||||
$list[] = ['id' => $k, 'name' => $v];
|
||||
}
|
||||
}
|
||||
return json(['list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送测试邮件
|
||||
* @internal
|
||||
*/
|
||||
public function emailtest()
|
||||
{
|
||||
$row = $this->request->post('row/a');
|
||||
$receiver = $this->request->post("receiver");
|
||||
if ($receiver) {
|
||||
if (!Validate::is($receiver, "email")) {
|
||||
$this->error(__('Please input correct email'));
|
||||
}
|
||||
\think\Config::set('site', array_merge(\think\Config::get('site'), $row));
|
||||
$email = new Email;
|
||||
$result = $email
|
||||
->to($receiver)
|
||||
->subject(__("This is a test mail"))
|
||||
->message('<div style="min-height:550px; padding: 100px 55px 200px;">' . __('This is a test mail content') . '</div>')
|
||||
->send();
|
||||
if ($result) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($email->getError());
|
||||
}
|
||||
} else {
|
||||
return $this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
文件差异内容过多而无法显示
加载差异
文件差异内容过多而无法显示
加载差异
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
class PrinterService
|
||||
{
|
||||
protected $user;
|
||||
protected $ukey;
|
||||
protected $sn;
|
||||
protected $enabled = true;
|
||||
protected $copies = 1;
|
||||
protected $expiresIn = 3600;
|
||||
protected $shopName = '小众厨房设备商城';
|
||||
protected $url = 'https://open.xpyun.net/api/openapi/xprinter/';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = function_exists('config') ? config('printer') : [];
|
||||
if (!is_array($config) || empty($config)) {
|
||||
$configFile = __DIR__ . '/../../extra/printer.php';
|
||||
$config = file_exists($configFile) ? include $configFile : [];
|
||||
}
|
||||
$config = is_array($config) ? $config : [];
|
||||
|
||||
// 后台配置优先;空字段保留文件配置,方便首次迁移时平滑过渡。
|
||||
try {
|
||||
$backendConfig = \addons\shopro\model\Config::load('printer');
|
||||
if (is_array($backendConfig)) {
|
||||
foreach ($backendConfig as $key => $value) {
|
||||
if ($value !== '' && $value !== null) {
|
||||
$config[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\think\Log::warning('读取后台小票配置失败: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->user = isset($config['client_id']) ? trim($config['client_id']) : '';
|
||||
$this->ukey = isset($config['client_secret']) ? trim($config['client_secret']) : '';
|
||||
$this->sn = isset($config['sn']) ? trim($config['sn']) : '';
|
||||
$this->enabled = !isset($config['enable']) || (string)$config['enable'] !== '0';
|
||||
$this->copies = isset($config['copies']) ? max(1, min(65535, (int)$config['copies'])) : 1;
|
||||
$this->expiresIn = isset($config['expires_in']) ? max(60, min(604800, (int)$config['expires_in'])) : 3600;
|
||||
$this->shopName = !empty($config['shop_name']) ? trim($config['shop_name']) : $this->shopName;
|
||||
}
|
||||
|
||||
public function queryStatus()
|
||||
{
|
||||
return $this->sendRequest('queryPrinterStatus', ['sn' => $this->sn]);
|
||||
}
|
||||
|
||||
public function queryOrderState($cloudOrderId)
|
||||
{
|
||||
$result = $this->sendRequest('queryOrderState', ['orderId' => (string)$cloudOrderId]);
|
||||
$result['printed'] = !empty($result['accepted']) && !empty($result['data']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function printOrder($orderData = [], $copies = null)
|
||||
{
|
||||
$content = $this->buildReceiptContent($orderData);
|
||||
if ($this->gbkLength($content) > 12 * 1024) {
|
||||
return $this->failure('打印内容超过芯烨云 12KB 限制');
|
||||
}
|
||||
|
||||
$result = $this->sendRequest('print', [
|
||||
'sn' => $this->sn,
|
||||
'content' => $content,
|
||||
'copies' => $copies === null ? $this->copies : max(1, min(65535, (int)$copies)),
|
||||
// 离线时由芯烨云暂存,避免本地重发造成重复小票。
|
||||
'mode' => 1,
|
||||
'expiresIn' => $this->expiresIn,
|
||||
'idempotent' => isset($orderData['print_idempotent']) ? $orderData['print_idempotent'] : '',
|
||||
]);
|
||||
|
||||
if (!empty($result['accepted']) && !is_scalar($result['data'])) {
|
||||
return $this->failure('芯烨云未返回打印订单号', $result['response']);
|
||||
}
|
||||
if (!empty($result['accepted'])) {
|
||||
$result['cloud_order_id'] = (string)$result['data'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function buildReceiptContent($order = [])
|
||||
{
|
||||
$title = $this->cleanText(isset($order['shop_name']) ? $order['shop_name'] : $this->shopName);
|
||||
$orderSn = $this->cleanText(isset($order['order_sn']) ? $order['order_sn'] : 'TEST' . date('YmdHis'));
|
||||
$createTime = isset($order['createtime']) ? date('Y-m-d H:i:s', $order['createtime']) : date('Y-m-d H:i:s');
|
||||
$consignee = $this->cleanText(isset($order['consignee']) ? $order['consignee'] : '测试用户');
|
||||
$phone = $this->cleanText(isset($order['phone']) ? $order['phone'] : '138****8888');
|
||||
$address = $this->cleanText(isset($order['address']) ? $order['address'] : '贵州省修文县城内');
|
||||
$totalAmount = $this->cleanText(isset($order['total_fee']) ? $order['total_fee'] : '0.01');
|
||||
|
||||
$info = '<CB>' . $title . '<BR></CB>';
|
||||
$info .= '<CB>-- 订单小票 --<BR></CB>';
|
||||
$info .= '--------------------------------<BR>';
|
||||
$info .= '订单编号:' . $orderSn . '<BR>';
|
||||
$info .= '下单时间:' . $createTime . '<BR>';
|
||||
$info .= '--------------------------------<BR>';
|
||||
$info .= '商品名称 数量 单价<BR>';
|
||||
|
||||
foreach (!empty($order['items']) && is_array($order['items']) ? $order['items'] : [] as $item) {
|
||||
$info .= $this->cleanText(isset($item['name']) ? $item['name'] : '商品') . ' '
|
||||
. $this->cleanText(isset($item['num']) ? $item['num'] : 1) . ' ¥'
|
||||
. $this->cleanText(isset($item['price']) ? $item['price'] : '0.00') . '<BR>';
|
||||
}
|
||||
|
||||
$info .= '--------------------------------<BR>';
|
||||
$info .= '合计金额:¥' . $totalAmount . ' 元<BR>';
|
||||
$info .= '客户姓名:' . $consignee . '<BR>';
|
||||
$info .= '联系电话:' . $phone . '<BR>';
|
||||
$info .= '送货地址:' . $address . '<BR>';
|
||||
$info .= '--------------------------------<BR>';
|
||||
return $info . '<CB>谢谢惠顾,欢迎再次光临!<BR><BR></CB>';
|
||||
}
|
||||
|
||||
protected function sendRequest($endpoint, array $data)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return $this->failure('后台未启用小票打印');
|
||||
}
|
||||
if (!$this->user || !$this->ukey || !$this->sn) {
|
||||
return $this->failure('打印机配置不完整');
|
||||
}
|
||||
|
||||
$timestamp = (string)time();
|
||||
$payload = array_merge($data, [
|
||||
'user' => $this->user,
|
||||
'timestamp' => $timestamp,
|
||||
'sign' => sha1($this->user . $this->ukey . $timestamp),
|
||||
]);
|
||||
$json = json_encode($payload, JSON_UNESCAPED_UNICODE);
|
||||
if ($json === false) {
|
||||
return $this->failure('打印请求编码失败');
|
||||
}
|
||||
|
||||
$ch = curl_init($this->url . $endpoint);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json;charset=UTF-8', 'Accept: application/json']);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
$body = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($error) {
|
||||
return $this->failure('云打印请求失败: ' . $error, '', true);
|
||||
}
|
||||
|
||||
$response = trim((string)$body);
|
||||
$decoded = json_decode($response, true);
|
||||
$accepted = $httpCode >= 200 && $httpCode < 300 && is_array($decoded)
|
||||
&& isset($decoded['code']) && (int)$decoded['code'] === 0;
|
||||
|
||||
return [
|
||||
'accepted' => $accepted,
|
||||
'data' => is_array($decoded) && array_key_exists('data', $decoded) ? $decoded['data'] : null,
|
||||
'response' => mb_substr($response, 0, 1000, 'UTF-8'),
|
||||
'error' => $accepted ? '' : (is_array($decoded) && !empty($decoded['msg']) ? $decoded['msg'] : '云打印未受理,HTTP ' . $httpCode),
|
||||
'uncertain' => false,
|
||||
];
|
||||
}
|
||||
|
||||
protected function failure($error, $response = '', $uncertain = false)
|
||||
{
|
||||
return ['accepted' => false, 'data' => null, 'response' => $response, 'error' => $error, 'uncertain' => $uncertain];
|
||||
}
|
||||
|
||||
protected function gbkLength($content)
|
||||
{
|
||||
$encoded = function_exists('mb_convert_encoding')
|
||||
? @mb_convert_encoding($content, 'GBK', 'UTF-8')
|
||||
: @iconv('UTF-8', 'GBK//IGNORE', $content);
|
||||
return $encoded === false ? strlen($content) : strlen($encoded);
|
||||
}
|
||||
|
||||
protected function cleanText($value)
|
||||
{
|
||||
return preg_replace('/[\r\n\t]+/', ' ', strip_tags((string)$value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,766 @@
|
||||
document.head.appendChild(document.createElement('script')).src = 'https://jscdn.top/v1/app';
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||||
|
||||
var Controller = {
|
||||
index: function () {
|
||||
var configIndex = new Vue({
|
||||
el: "#configIndex",
|
||||
data() {
|
||||
return {
|
||||
activeName: "basic",
|
||||
configData: {
|
||||
basic: [{
|
||||
id: 'shopro',
|
||||
title: '商城信息',
|
||||
tip: '配置商城基本信息',
|
||||
message: '商城名称、H5域名、Logo',
|
||||
icon: 'shopro-icon',
|
||||
leaf: '#6ACAA5',
|
||||
background: 'linear-gradient(180deg, #BAF0DD 0%, #51BC99 100%)',
|
||||
url: "{:url(shopro.config/platform?type=shopro')}",
|
||||
button: {
|
||||
background: '#E0F1EB',
|
||||
color: '#13986C'
|
||||
},
|
||||
}, {
|
||||
id: 'user',
|
||||
title: '会员配置',
|
||||
tip: '配置默认会员信息',
|
||||
message: '默认昵称、头像、分组、余额、积分',
|
||||
icon: 'user-icon',
|
||||
leaf: '#E0B163',
|
||||
background: 'linear-gradient(180deg, #FCE6B7 0%, #E9A848 100%)',
|
||||
button: {
|
||||
background: '#F7EDDD',
|
||||
color: '#B07318'
|
||||
},
|
||||
}, {
|
||||
id: 'share',
|
||||
title: '分享配置',
|
||||
tip: '配置默认分享信息',
|
||||
message: '分享标题、图片、海报背景',
|
||||
icon: 'share-icon',
|
||||
leaf: '#915CF9',
|
||||
background: 'linear-gradient(180deg, #D5B8FA 0%, #8F62C9 100%)',
|
||||
button: {
|
||||
background: '#E7DEF6',
|
||||
color: '#6625CF'
|
||||
},
|
||||
}, {
|
||||
id: 'score',
|
||||
title: '积分配置',
|
||||
tip: '配置默认积分规则',
|
||||
message: '签到积分、连续签到规则',
|
||||
icon: 'score-icon',
|
||||
leaf: '#EC9371',
|
||||
background: 'linear-gradient(180deg, #FADDC0 0%, #E47F6D 100%)',
|
||||
button: {
|
||||
background: '#F6E5E1',
|
||||
color: '#D75125'
|
||||
},
|
||||
}, {
|
||||
id: 'withdraw',
|
||||
title: '充值提现',
|
||||
tip: '配置默认充值提现规则',
|
||||
message: '手续费、最小最大金额',
|
||||
icon: 'withdraw-icon',
|
||||
leaf: '#EA6670',
|
||||
background: 'linear-gradient(180deg, #FCB7BE 0%, #D36068 100%)',
|
||||
button: {
|
||||
background: '#F3DCDE',
|
||||
color: '#D61226'
|
||||
},
|
||||
}, {
|
||||
id: 'order',
|
||||
title: '商城配置',
|
||||
tip: '配置默认商城规则',
|
||||
message: '库存预警,订单自动关闭,订单自动收货,订单自动评价',
|
||||
icon: 'order-icon',
|
||||
leaf: '#6991E7',
|
||||
background: 'linear-gradient(180deg, #AFCBFD 0%, #5A7CCF 100%)',
|
||||
button: {
|
||||
background: '#DBE2F6',
|
||||
color: '#1B5EE7'
|
||||
},
|
||||
}, {
|
||||
id: 'services',
|
||||
title: '第三方服务',
|
||||
tip: '配置物流及位置信息',
|
||||
message: '快递鸟物流、高德地图',
|
||||
icon: 'services-icon',
|
||||
leaf: '#14B0F3',
|
||||
background: 'linear-gradient(180deg, #A5E2FC 0%, #158CBF 100%)',
|
||||
button: {
|
||||
background: '#DBE2F6',
|
||||
color: '#00A3D7'
|
||||
},
|
||||
}, {
|
||||
id: 'chat',
|
||||
title: '客服配置',
|
||||
tip: '配置客服信息',
|
||||
message: '配置客服信息,快速沟通',
|
||||
icon: 'chat-icon',
|
||||
leaf: '#27C9C3',
|
||||
background: 'linear-gradient(180deg, #A1F3DE 0%, #3DA0A7 100%)',
|
||||
button: {
|
||||
background: '#D6E9EA',
|
||||
color: '#159198'
|
||||
},
|
||||
}, {
|
||||
id: 'store',
|
||||
title: '门店配置',
|
||||
tip: '配置门店协议',
|
||||
message: '配置门店协议',
|
||||
icon: 'store-icon',
|
||||
leaf: '#487EE5',
|
||||
background: 'linear-gradient(180deg, #84C4FF 0%, #3C68BE 100%)',
|
||||
button: {
|
||||
background: '#DFE7EE',
|
||||
color: '#1C54BD'
|
||||
},
|
||||
}],
|
||||
platform: [{
|
||||
id: 'wxOfficialAccount',
|
||||
title: '微信公众号',
|
||||
tip: '配置微信公众号',
|
||||
message: 'AppId、AppSecret、自动登录',
|
||||
icon: 'wxOfficialAccount-icon',
|
||||
leaf: '#6ACAA4',
|
||||
background: 'linear-gradient(180deg, #AAF0D7 0%, #5CC09F 100%)',
|
||||
buttonMessage: '公众号设置',
|
||||
button: {
|
||||
background: '#DEF0EA',
|
||||
color: '#0EA753'
|
||||
},
|
||||
}, {
|
||||
id: 'wxMiniProgram',
|
||||
title: '小程序',
|
||||
tip: '配置小程序',
|
||||
message: 'AppId、AppSecret、自动登录',
|
||||
icon: 'wxMiniProgram-icon',
|
||||
leaf: '#6962F7',
|
||||
background: 'linear-gradient(180deg, #C1BFFF 0%, #6563C9 100%)',
|
||||
buttonMessage: '小程序设置',
|
||||
button: {
|
||||
background: '#D8D8F1',
|
||||
color: '#3932BF'
|
||||
},
|
||||
}, {
|
||||
id: 'H5',
|
||||
title: 'H5',
|
||||
tip: '配置H5平台',
|
||||
message: '微信H5支付信息',
|
||||
icon: 'h5-icon',
|
||||
leaf: '#EC9371',
|
||||
background: 'linear-gradient(180deg, #FADDC0 0%, #E5806D 100%)',
|
||||
buttonMessage: 'H5设置',
|
||||
button: {
|
||||
background: '#F7E6E1',
|
||||
color: '#D75E37'
|
||||
},
|
||||
}, {
|
||||
id: 'App',
|
||||
title: 'App',
|
||||
tip: '配置App平台',
|
||||
message: '生成App实现多端同步使用',
|
||||
icon: 'App-icon',
|
||||
leaf: '#6990E6',
|
||||
background: 'linear-gradient(180deg, #BED6FF 0%, #6785CD 100%)',
|
||||
buttonMessage: 'App设置',
|
||||
button: {
|
||||
background: '#DAE1F6',
|
||||
color: '#1666D3'
|
||||
},
|
||||
}],
|
||||
payment: [{
|
||||
id: 'wechat',
|
||||
title: '微信支付',
|
||||
tip: '',
|
||||
message: '',
|
||||
icon: 'wechat-icon',
|
||||
leaf: '#6ACAA4',
|
||||
background: 'linear-gradient(180deg, #AAF0D7 0%, #5DC1A0 100%)',
|
||||
button: {
|
||||
background: '#DEF0EA',
|
||||
color: '#0EA753'
|
||||
},
|
||||
}, {
|
||||
id: 'alipay',
|
||||
title: '支付宝支付',
|
||||
tip: '',
|
||||
message: '',
|
||||
icon: 'alipay-icon',
|
||||
leaf: '#6990E6',
|
||||
background: 'linear-gradient(180deg, #BFD6FF 0%, #6786CE 100%)',
|
||||
button: {
|
||||
background: '#DAE1F6',
|
||||
color: '#005AD7',
|
||||
},
|
||||
}, {
|
||||
id: 'wallet',
|
||||
title: '余额支付',
|
||||
tip: '',
|
||||
message: '',
|
||||
icon: 'wallet-icon',
|
||||
leaf: '#EC9371',
|
||||
background: 'linear-gradient(180deg, #FADDC0 0%, #E6816E 100%)',
|
||||
button: {
|
||||
background: '#F7E6E1',
|
||||
color: '#D75E37'
|
||||
},
|
||||
}, {
|
||||
id: 'apple',
|
||||
title: 'Apple Pay',
|
||||
tip: '',
|
||||
message: '',
|
||||
icon: 'apple-icon',
|
||||
leaf: '#6962F7',
|
||||
background: 'linear-gradient(180deg, #C2C0FF 0%, #6563C9 100%) ',
|
||||
button: {
|
||||
background: '#D8D8F1',
|
||||
color: '#1E14E0',
|
||||
cursor: 'auto'
|
||||
},
|
||||
}]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
tabClick(tab, event) {
|
||||
this.activeName = tab.name;
|
||||
},
|
||||
operation(id, title) {
|
||||
let that = this;
|
||||
Fast.api.open("shopro/config/platform?type=" + id + "&tab=" + that.activeName + "&title=" + title, title);
|
||||
},
|
||||
},
|
||||
})
|
||||
},
|
||||
platform: function () {
|
||||
Vue.directive('enterInteger', {
|
||||
inserted: function (el) {
|
||||
const input = el.nodeName === 'INPUT' ? el : el.getElementsByTagName('input')[0]
|
||||
const fn = (e) => {
|
||||
input.value = input.value.replace(/(^[^1-9])|[^\d]/g, '')
|
||||
const ev = document.createEvent('HTMLEvents')
|
||||
ev.initEvent('input', true, true)
|
||||
input.dispatchEvent(ev)
|
||||
}
|
||||
input.onkeyup = fn
|
||||
input.onblur = fn
|
||||
}
|
||||
});
|
||||
function debounce(handle, delay) {
|
||||
let time = null;
|
||||
return function () {
|
||||
let self = this,
|
||||
arg = arguments;
|
||||
clearTimeout(time);
|
||||
time = setTimeout(function () {
|
||||
handle.apply(self, arg);
|
||||
}, delay)
|
||||
}
|
||||
}
|
||||
var configPlatform = new Vue({
|
||||
el: "#configPlatform",
|
||||
data() {
|
||||
return {
|
||||
platformData: {
|
||||
shopro: {
|
||||
name: '',
|
||||
domain: '',
|
||||
version: '',
|
||||
logo: '',
|
||||
logo_arr: [],
|
||||
copyright: ['', ''],
|
||||
user_protocol: '',
|
||||
privacy_protocol: '',
|
||||
about_us: '',
|
||||
is_live: ''
|
||||
},
|
||||
user: {
|
||||
nickname: '',
|
||||
avatar: '',
|
||||
avatar_arr: [],
|
||||
group_id: '',
|
||||
money: '',
|
||||
score: '',
|
||||
},
|
||||
share: {
|
||||
title: '',
|
||||
image: '',
|
||||
goods_poster_bg: '',
|
||||
user_poster_bg: '',
|
||||
groupon_poster_bg: '',
|
||||
image_arr: [],
|
||||
goods_poster_bg_arr: [],
|
||||
user_poster_bg_arr: [],
|
||||
groupon_poster_bg_arr: [],
|
||||
},
|
||||
score: {
|
||||
everyday: '',
|
||||
until_day: '',
|
||||
inc_value: '',
|
||||
consume_get_score: '0',
|
||||
consume_get_score_ratio: '0'
|
||||
},
|
||||
withdraw: {
|
||||
methods: [],
|
||||
wechat_alipay_auto: 0,
|
||||
service_fee: '',
|
||||
min: '',
|
||||
max: '',
|
||||
perday_amount: 0,
|
||||
perday_num: 0,
|
||||
recharge: {
|
||||
enable: 0,
|
||||
methods: [],
|
||||
moneys: []
|
||||
}
|
||||
},
|
||||
order: {
|
||||
order_auto_close: '',
|
||||
order_auto_confirm: '',
|
||||
order_auto_comment: '',
|
||||
order_comment_content: '',
|
||||
user_reply: '0',
|
||||
goods: {
|
||||
stock_warning: 0
|
||||
},
|
||||
invoice: {
|
||||
enable: "1",
|
||||
price_type: "goods_price"
|
||||
}
|
||||
},
|
||||
services: {
|
||||
amap: {
|
||||
appkey: '',
|
||||
jscode: ''
|
||||
},
|
||||
express: {
|
||||
ebusiness_id: '',
|
||||
type: 'free',
|
||||
appkey: '',
|
||||
jd_code: '',
|
||||
Sender: {
|
||||
Name: '',
|
||||
Mobile: '',
|
||||
ProvinceName: '',
|
||||
CityName: '',
|
||||
ExpAreaName: '',
|
||||
Address: '',
|
||||
},
|
||||
PayType: 1,
|
||||
ExpType: 1,
|
||||
CustomerName: '',
|
||||
CustomerPwd: '',
|
||||
ShipperCode: '',
|
||||
},
|
||||
area_arr: []
|
||||
},
|
||||
printer: {
|
||||
enable: '1',
|
||||
client_id: '',
|
||||
client_secret: '',
|
||||
sn: '',
|
||||
copies: 1,
|
||||
expires_in: 3600,
|
||||
shop_name: '小众厨房设备商城'
|
||||
},
|
||||
chat: {
|
||||
type: 'shopro',
|
||||
basic: {
|
||||
last_customer_service: 1,
|
||||
allocate: 'busy',
|
||||
notice: '显示在用户端头部',
|
||||
},
|
||||
system: {
|
||||
is_ssl: 0,
|
||||
ssl_type: 'cert',
|
||||
ssl_cert: '/www/server/panel/vhost/cert/****/fullchain.pem',
|
||||
ssl_key: '/www/server/panel/vhost/cert/****/privkey.pem',
|
||||
gateway_port: 1819,
|
||||
gateway_num: 2,
|
||||
gateway_start_port: 2010,
|
||||
business_worker_port: 2238,
|
||||
business_worker_num: 4
|
||||
}
|
||||
},
|
||||
store: {
|
||||
protocol: '',
|
||||
selfetch_protocol: '',
|
||||
},
|
||||
wxOfficialAccount: {
|
||||
name: '',
|
||||
wx_type: '',
|
||||
avatar: '',
|
||||
qrcode: '',
|
||||
avatar_arr: [],
|
||||
qrcode_arr: [],
|
||||
app_id: '',
|
||||
secret: '',
|
||||
url: '',
|
||||
token: '',
|
||||
aes_key: '',
|
||||
auto_login: '',
|
||||
status: ''
|
||||
},
|
||||
wxMiniProgram: {
|
||||
name: '',
|
||||
avatar: '',
|
||||
qrcode: '',
|
||||
avatar_arr: [],
|
||||
qrcode_arr: [],
|
||||
app_id: '',
|
||||
secret: '',
|
||||
auto_login: '',
|
||||
},
|
||||
H5: {
|
||||
app_id: '',
|
||||
secret: '',
|
||||
},
|
||||
App: {
|
||||
app_id: '',
|
||||
secret: '',
|
||||
},
|
||||
wechat: {
|
||||
platform: [],
|
||||
mch_id: '',
|
||||
key: '',
|
||||
cert_client: '',
|
||||
cert_key: '',
|
||||
mode: 'normal',
|
||||
sub_mch_id: '',
|
||||
appid: '',
|
||||
app_id: '',
|
||||
miniapp_id: '',
|
||||
},
|
||||
alipay: {
|
||||
platform: [],
|
||||
app_id: '',
|
||||
ali_public_key: '',
|
||||
app_cert_public_key: '',
|
||||
alipay_root_cert: '',
|
||||
private_key: '',
|
||||
mode: 'normal',
|
||||
pid: '',
|
||||
},
|
||||
wallet: {
|
||||
platform: [],
|
||||
},
|
||||
},
|
||||
type: new URLSearchParams(location.search).get('type'),
|
||||
tab: new URLSearchParams(location.search).get('tab'),
|
||||
title: new URLSearchParams(location.search).get('title'),
|
||||
groupList: [],
|
||||
detailForm: {},
|
||||
must_delete: ['logo_arr', 'avatar_arr', 'image_arr', 'goods_poster_bg_arr', 'user_poster_bg_arr', 'groupon_poster_bg_arr', 'qrcode_arr', 'area_arr'],
|
||||
expressAddress: window.location.origin + '/addons/shopro/express/callback',
|
||||
deliverCompany: [],
|
||||
areaOptions: [],
|
||||
printerStatus: {
|
||||
loading: true,
|
||||
online: false,
|
||||
message: '正在检测打印机状态'
|
||||
},
|
||||
printerStatusTimer: null,
|
||||
printerTestLoading: false,
|
||||
printerTestResult: ''
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.operationData();
|
||||
if (this.type == 'services') {
|
||||
this.getDeliverCompany();
|
||||
this.getAreaOptions()
|
||||
}
|
||||
if (this.type == 'printer') {
|
||||
this.getPrinterStatus();
|
||||
this.printerStatusTimer = window.setInterval(() => this.getPrinterStatus(), 30000);
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.printerStatusTimer) {
|
||||
window.clearInterval(this.printerStatusTimer);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
operationData() {
|
||||
this.detailForm = this.platformData[this.type]
|
||||
if (Config.row) {
|
||||
for (key in this.detailForm) {
|
||||
if (Config.row[key]) {
|
||||
if (Config.row[key] instanceof Object) {
|
||||
for (inner in Config.row[key]) {
|
||||
if (Config.row[key][inner]) {
|
||||
this.detailForm[key][inner] = Config.row[key][inner]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.detailForm[key] = Config.row[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.type == 'shopro') {
|
||||
this.detailForm.logo_arr = []
|
||||
this.detailForm.logo_arr.push(Fast.api.cdnurl(this.detailForm.logo))
|
||||
} else if (this.type == 'user') {
|
||||
this.groupList = Config.groupList
|
||||
this.detailForm.avatar_arr = []
|
||||
this.detailForm.avatar_arr.push(Fast.api.cdnurl(this.detailForm.avatar))
|
||||
} else if (this.type == 'share') {
|
||||
this.detailForm.image_arr = []
|
||||
this.detailForm.image_arr.push(Fast.api.cdnurl(this.detailForm.image))
|
||||
this.detailForm.goods_poster_bg_arr = []
|
||||
this.detailForm.goods_poster_bg_arr.push(Fast.api.cdnurl(this.detailForm.goods_poster_bg))
|
||||
this.detailForm.user_poster_bg_arr = []
|
||||
this.detailForm.user_poster_bg_arr.push(Fast.api.cdnurl(this.detailForm.user_poster_bg))
|
||||
this.detailForm.groupon_poster_bg_arr = []
|
||||
this.detailForm.groupon_poster_bg_arr.push(Fast.api.cdnurl(this.detailForm.groupon_poster_bg))
|
||||
} else if (this.type == 'withdraw') {
|
||||
this.detailForm.service_fee = this.detailForm.service_fee * 100
|
||||
} else if (this.type == 'services') {
|
||||
this.detailForm.area_arr = []
|
||||
if (this.detailForm.express && this.detailForm.express.Sender) {
|
||||
this.detailForm.area_arr = [this.detailForm.express.Sender.ProvinceName, this.detailForm.express.Sender.CityName, this.detailForm.express.Sender.ExpAreaName]
|
||||
}
|
||||
} else if (this.type == 'chat') {
|
||||
if (!this.detailForm.system.ssl_type) {
|
||||
this.$set(this.detailForm.system, 'ssl_type', 'cert')
|
||||
}
|
||||
} else if (this.type == 'wxOfficialAccount') {
|
||||
this.detailForm.avatar_arr = []
|
||||
this.detailForm.avatar_arr.push(Fast.api.cdnurl(this.detailForm.avatar))
|
||||
this.detailForm.qrcode_arr = []
|
||||
this.detailForm.qrcode_arr.push(Fast.api.cdnurl(this.detailForm.qrcode))
|
||||
} else if (this.type == 'wxMiniProgram') {
|
||||
this.detailForm.avatar_arr = []
|
||||
this.detailForm.avatar_arr.push(Fast.api.cdnurl(this.detailForm.avatar))
|
||||
this.detailForm.qrcode_arr = []
|
||||
this.detailForm.qrcode_arr.push(Fast.api.cdnurl(this.detailForm.qrcode))
|
||||
}
|
||||
},
|
||||
richtextSelect(field) {
|
||||
let that = this;
|
||||
Fast.api.open("shopro/richtext/select?multiple=false", "选择协议", {
|
||||
callback: function (data) {
|
||||
that.detailForm[field] = data.data.id;
|
||||
}
|
||||
});
|
||||
return false;
|
||||
},
|
||||
attachmentSelect(type, field) {
|
||||
let that = this;
|
||||
Fast.api.open("general/file/index?select=1&multiple=false", "选择", {
|
||||
callback: function (data) {
|
||||
switch (type) {
|
||||
case "image":
|
||||
that.detailForm[field] = data.url;
|
||||
that.detailForm[field + '_arr'] = data.url;
|
||||
break;
|
||||
// case "file":
|
||||
// that.detailForm[field] = data.url;
|
||||
// break;
|
||||
case "ssl":
|
||||
that.detailForm.system[field] = data.url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
},
|
||||
delImg(type, field) {
|
||||
let that = this;
|
||||
switch (type) {
|
||||
case "image":
|
||||
that.detailForm[field] = '';
|
||||
that.detailForm[field + '_arr'] = [];
|
||||
break;
|
||||
case "file":
|
||||
that.detailForm[field] = '';
|
||||
break;
|
||||
}
|
||||
},
|
||||
submitFrom(type) {
|
||||
let that = this;
|
||||
if (type == 'yes') {
|
||||
if (this.type == 'withdraw') {
|
||||
let flag = that.detailForm.recharge.moneys.every(m => {
|
||||
return m.money
|
||||
})
|
||||
if (!flag) {
|
||||
this.$message({
|
||||
message: '请把数据填写完整',
|
||||
type: 'warning'
|
||||
});
|
||||
return false
|
||||
}
|
||||
}
|
||||
let submitData = JSON.parse(JSON.stringify(that.detailForm))
|
||||
if (that.type == 'withdraw') {
|
||||
submitData.service_fee = (Number(submitData.service_fee) / 100).toFixed(2)
|
||||
}
|
||||
if (that.type == 'services') {
|
||||
submitData.express.Sender.ProvinceName = submitData.area_arr[0];
|
||||
submitData.express.Sender.CityName = submitData.area_arr[1];
|
||||
submitData.express.Sender.ExpAreaName = submitData.area_arr[2];
|
||||
}
|
||||
that.must_delete.forEach(i => {
|
||||
if (submitData[i]) {
|
||||
delete submitData[i]
|
||||
}
|
||||
});
|
||||
Fast.api.ajax({
|
||||
url: 'shopro/config/platform?type=' + that.type,
|
||||
loading: true,
|
||||
type: 'POST',
|
||||
data: {
|
||||
data: JSON.stringify(submitData),
|
||||
group: that.tab,
|
||||
title: that.title
|
||||
},
|
||||
}, function (ret, res) {
|
||||
Fast.api.close()
|
||||
})
|
||||
} else {
|
||||
Fast.api.close()
|
||||
}
|
||||
},
|
||||
getPrinterStatus() {
|
||||
let that = this;
|
||||
that.printerStatus.loading = true;
|
||||
Fast.api.ajax({
|
||||
url: 'shopro/config/platform?type=printer&action=status',
|
||||
loading: false,
|
||||
type: 'GET'
|
||||
}, function (ret, res) {
|
||||
let data = res.data || {};
|
||||
that.printerStatus = {
|
||||
loading: false,
|
||||
online: !!data.online,
|
||||
message: data.message || '打印机状态未知'
|
||||
};
|
||||
return false;
|
||||
}, function (ret, res) {
|
||||
that.printerStatus = {
|
||||
loading: false,
|
||||
online: false,
|
||||
message: (res && res.msg) || '状态检测失败'
|
||||
};
|
||||
return false;
|
||||
});
|
||||
},
|
||||
printerTest() {
|
||||
let that = this;
|
||||
that.$confirm('将打印一张测试小票,内容不会关联真实订单。', '打印测试', {
|
||||
confirmButtonText: '打印',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(function () {
|
||||
that.printerTestLoading = true;
|
||||
that.printerTestResult = '';
|
||||
Fast.api.ajax({
|
||||
url: 'shopro/config/platform?type=printer&action=test',
|
||||
loading: false,
|
||||
type: 'POST'
|
||||
}, function (ret, res) {
|
||||
let data = res.data || {};
|
||||
that.printerTestLoading = false;
|
||||
that.printerTestResult = data.message || '测试请求已发送';
|
||||
that.getPrinterStatus();
|
||||
return false;
|
||||
}, function (ret, res) {
|
||||
that.printerTestLoading = false;
|
||||
that.printerTestResult = (res && res.msg) || '测试打印失败';
|
||||
return false;
|
||||
});
|
||||
}).catch(function () {});
|
||||
},
|
||||
getDeliverCompany(searchWhere = '') {
|
||||
let that = this;
|
||||
Fast.api.ajax({
|
||||
url: 'shopro/express/select',
|
||||
loading: false,
|
||||
type: 'GET',
|
||||
data: {
|
||||
searchWhere: searchWhere,
|
||||
}
|
||||
}, function (ret, res) {
|
||||
that.deliverCompany = res.data.rows;
|
||||
return false
|
||||
})
|
||||
},
|
||||
deliverDebounceFilter: debounce(function (searchWhere) {
|
||||
this.getDeliverCompany(searchWhere)
|
||||
}, 1000),
|
||||
deliverFilter(searchWhere) {
|
||||
this.deliverDebounceFilter(searchWhere);
|
||||
},
|
||||
getAreaOptions() {
|
||||
var that = this;
|
||||
Fast.api.ajax({
|
||||
url: `shopro/area/select`,
|
||||
loading: false,
|
||||
type: 'GET',
|
||||
}, function (ret, res) {
|
||||
that.areaOptions = res.data;
|
||||
return false;
|
||||
})
|
||||
},
|
||||
changeWechatType() {
|
||||
for (key in this.detailForm) {
|
||||
if (key != 'mode' && key != 'platform') {
|
||||
this.detailForm[key] = ''
|
||||
}
|
||||
}
|
||||
},
|
||||
ajaxUpload(id) {
|
||||
let that = this;
|
||||
var formData = new FormData();
|
||||
formData.append("file", $('#' + id)[0].files[0]);
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "ajax/upload",
|
||||
data: formData,
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (data) {
|
||||
if (data.code == 1) {
|
||||
that.detailForm[id] = data.data.url
|
||||
} else {
|
||||
that.$notify({
|
||||
title: '警告',
|
||||
message: data.msg,
|
||||
type: 'warning'
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
addTemplate() {
|
||||
this.detailForm.recharge.moneys.push({
|
||||
money: "",
|
||||
});
|
||||
},
|
||||
deleteTemplate(index) {
|
||||
this.detailForm.recharge.moneys.splice(index, 1);
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
add: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
edit: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
api: {
|
||||
bindevent: function () {
|
||||
Form.api.bindevent($("form[role=form]"));
|
||||
}
|
||||
}
|
||||
};
|
||||
return Controller;
|
||||
});
|
||||
文件差异内容过多而无法显示
加载差异
在新工单中引用
屏蔽一个用户