Commit 70a9a8dd authored by jianghaiming's avatar jianghaiming

Merge branch 'test' of https://gitlab.yidian-inc.com/bp/goods into test

parents dfbfb97d 5303e2a5
...@@ -33,11 +33,11 @@ class BaseException extends \Exception ...@@ -33,11 +33,11 @@ class BaseException extends \Exception
$this->msg = $params['msg'] ?? Registry::get('config')->exception->user->msg; $this->msg = $params['msg'] ?? Registry::get('config')->exception->user->msg;
if (isset($params['cus']) && $this->cus && isset($this->cus[intval($params['cus'])]) && $this->base_code) { if (isset($params['cus']) && $this->cus && isset($this->cus[intval($params['cus'])]) && $this->base_code) {
return $this->setCusMsg($params['cus']); return $this->setCusMsg($params['cus'],$params['data']??'');
} }
} }
public function setCusMsg($cus) public function setCusMsg($cus,$data = '')
{ {
//每个服务都有自己的codePrefix //每个服务都有自己的codePrefix
$appid = \Yaf\Application::app()->getConfig()->get("appid"); $appid = \Yaf\Application::app()->getConfig()->get("appid");
...@@ -48,7 +48,7 @@ class BaseException extends \Exception ...@@ -48,7 +48,7 @@ class BaseException extends \Exception
$base_code = intval($this->base_code); $base_code = intval($this->base_code);
$this->code = $codePrefix + $base_code + $cus_code; $this->code = $codePrefix + $base_code + $cus_code;
$this->msg = isset($params['data']) ? vsprintf($this->cus[$cus_code],$params['data']) : $this->cus[$cus_code]; $this->msg = !empty($data) ? vsprintf($this->cus[$cus_code],$data) : $this->cus[$cus_code];
} }
public function __get($name): bool public function __get($name): bool
......
...@@ -18,6 +18,7 @@ class GoodsException extends BaseException ...@@ -18,6 +18,7 @@ class GoodsException extends BaseException
const NOT_FIND_MARKETING = 51; const NOT_FIND_MARKETING = 51;
const LABEL_PRINTER_ALREADY_EXIST = 53; const LABEL_PRINTER_ALREADY_EXIST = 53;
const PRINTER_BIND_ERROR = 54; const PRINTER_BIND_ERROR = 54;
const PRINTER_SN_ERROR = 55;
protected $cus = [ protected $cus = [
0 => '商品创建失败,请稍后重试', 0 => '商品创建失败,请稍后重试',
...@@ -75,5 +76,6 @@ class GoodsException extends BaseException ...@@ -75,5 +76,6 @@ class GoodsException extends BaseException
52 => '过期时间不得小于等于上架开始时间', 52 => '过期时间不得小于等于上架开始时间',
self::LABEL_PRINTER_ALREADY_EXIST => '标签打印机已被%s绑定', self::LABEL_PRINTER_ALREADY_EXIST => '标签打印机已被%s绑定',
self::PRINTER_BIND_ERROR => '打印机绑定失败:%s', self::PRINTER_BIND_ERROR => '打印机绑定失败:%s',
self::PRINTER_SN_ERROR => '打印机sn号码有误',
]; ];
} }
\ No newline at end of file
...@@ -41,7 +41,7 @@ class BaseValidate extends Validate ...@@ -41,7 +41,7 @@ class BaseValidate extends Validate
protected function isMobile($value) protected function isMobile($value)
{ {
$rule = '^1(3|4|5|7|8)[0-9]\d{8}$^'; $rule = '^1(3|4|5|6|7|8|9)[0-9]\d{8}$^';
$result = preg_match($rule, $value); $result = preg_match($rule, $value);
if ($result) { if ($result) {
return true; return true;
......
...@@ -14,10 +14,10 @@ class OtaValidate extends \Validate\BaseValidate ...@@ -14,10 +14,10 @@ class OtaValidate extends \Validate\BaseValidate
protected $rule = [ protected $rule = [
'ota_name' => 'require', 'ota_name' => 'require',
'ota_id' => 'require', 'ota_id' => 'require',
'address' => 'require', // 'address' => 'require',
'location' => 'require', // 'location' => 'require',
'longitude' => 'require', // 'longitude' => 'require',
'latitude' => 'require', // 'latitude' => 'require',
'offset' => 'egt:0', 'offset' => 'egt:0',
'limit' => 'elt:100', 'limit' => 'elt:100',
]; ];
...@@ -42,19 +42,32 @@ class OtaValidate extends \Validate\BaseValidate ...@@ -42,19 +42,32 @@ class OtaValidate extends \Validate\BaseValidate
public function sceneAdd() public function sceneAdd()
{ {
return $this->only(['ota_name', 'address','longitude','latitude', 'location']); return $this->only(['ota_name']);
} }
public function sceneDelete() public function sceneDelete()
{ {
return $this->only(['ota_id']); return $this->only(['ota_id']);
} }
public function sceneUndelete()
{
return $this->only(['ota_id']);
}
public function sceneUpdate() public function sceneUpdate()
{ {
return $this->only(['ota_id', 'ota_name', 'address','longitude','latitude', 'location']); return $this->only(['ota_id', 'ota_name']);
} }
public function sceneListByIds() public function sceneListByIds()
{ {
return $this->only(['ota_id']); return $this->only(['ota_id']);
} }
public function is_label_printer_sn($value){
if( substr($value, 3, 1) != '2' ){
return false;
}
return true;
}
} }
\ No newline at end of file
...@@ -24,9 +24,10 @@ class OtaController extends Base ...@@ -24,9 +24,10 @@ class OtaController extends Base
$printerKey = $this->params['printer_key'] ?? ''; $printerKey = $this->params['printer_key'] ?? '';
$labelPrinterSn = $this->params['label_printer_sn'] ?? ''; $labelPrinterSn = $this->params['label_printer_sn'] ?? '';
$labelPrinterKey = $this->params['label_printer_key'] ?? ''; $labelPrinterKey = $this->params['label_printer_key'] ?? '';
$isNormal = $this->params['is_normal'] ?? false;
$offset = $this->params['offset'] ?? 0; $offset = $this->params['offset'] ?? 0;
$limit = $this->params['limit'] ?? 20; $limit = $this->params['limit'] ?? 20;
$res = OtaService::list($name, $printerSn, $printerKey,$labelPrinterSn, $labelPrinterKey, $offset, $limit); $res = OtaService::list($name, $printerSn, $printerKey,$labelPrinterSn, $labelPrinterKey, $isNormal, $offset, $limit);
$this->success(['result' => $res]); $this->success(['result' => $res]);
} }
...@@ -69,6 +70,18 @@ class OtaController extends Base ...@@ -69,6 +70,18 @@ class OtaController extends Base
$this->success(['status' => $res ? 'success' : 'failed']); $this->success(['status' => $res ? 'success' : 'failed']);
} }
/**
* 删除一个供应商
* @throws \App\Exception\custom\ParamException
*/
public function undeleteAction()
{
(new OtaValidate())->scene('undelete')->validate();
$res = OtaService::undeleteOne($this->params['ota_id']);
$this->success(['status' => $res ? 'success' : 'failed']);
}
/** /**
* 更新供应商 * 更新供应商
...@@ -77,7 +90,7 @@ class OtaController extends Base ...@@ -77,7 +90,7 @@ class OtaController extends Base
public function updateAction() public function updateAction()
{ {
(new OtaValidate())->scene('update')->validate(); (new OtaValidate())->scene('update')->validate();
$res = OtaService::update($this->params); $res = OtaService::update($this->params, true);
$this->success(['status' => $res ? 'success' : 'failed']); $this->success(['status' => $res ? 'success' : 'failed']);
} }
......
...@@ -5,6 +5,7 @@ namespace App\Services\goods; ...@@ -5,6 +5,7 @@ namespace App\Services\goods;
use App\Exception\custom\GoodsException; use App\Exception\custom\GoodsException;
use App\Models\goods\mysql\Ota; use App\Models\goods\mysql\Ota;
use Api\PhpServices\Printer\PrinterFactory; use Api\PhpServices\Printer\PrinterFactory;
use Validate\OtaValidate;
class OtaService class OtaService
{ {
...@@ -18,7 +19,7 @@ class OtaService ...@@ -18,7 +19,7 @@ class OtaService
* @param int $limit * @param int $limit
* @return \Api\PhpUtils\Mysql\MysqlBase * @return \Api\PhpUtils\Mysql\MysqlBase
*/ */
public static function list($otaName='',$printerSN='',$printerKey='', $labelPrinterSN='',$labelPrinterKey='',$offset=0,$limit=20) public static function list($otaName='',$printerSN='',$printerKey='', $labelPrinterSN='',$labelPrinterKey='', $isNormal = false,$offset=0,$limit=20)
{ {
$otaName && $where['ota_name'] = $otaName; $otaName && $where['ota_name'] = $otaName;
$printerSN && $where["printer_sn"] = $printerSN; $printerSN && $where["printer_sn"] = $printerSN;
...@@ -26,7 +27,7 @@ class OtaService ...@@ -26,7 +27,7 @@ class OtaService
$labelPrinterSN && $where["label_printer_sn"] = $labelPrinterSN; $labelPrinterSN && $where["label_printer_sn"] = $labelPrinterSN;
$labelPrinterKey && $where['label_printer_key'] = $labelPrinterKey; $labelPrinterKey && $where['label_printer_key'] = $labelPrinterKey;
// $where['status'] = Ota::STATUS_NORMAL; $isNormal &&$where['status'] = Ota::STATUS_NORMAL;
$where['ORDER'] = ['ota_id' => 'DESC']; $where['ORDER'] = ['ota_id' => 'DESC'];
$where['LIMIT'] = [$offset, $limit]; $where['LIMIT'] = [$offset, $limit];
...@@ -77,8 +78,10 @@ class OtaService ...@@ -77,8 +78,10 @@ class OtaService
//检查打印机是否已存在 -- 打印机已被(商家名称)绑定 //检查打印机是否已存在 -- 打印机已被(商家名称)绑定
if(isset($params['printer_sn']) && $params['printer_sn']) { if(isset($params['printer_sn']) && $params['printer_sn']) {
if ((new OtaValidate())->is_label_printer_sn($params['printer_sn'])) {
throw new GoodsException(['cus' => GoodsException::PRINTER_SN_ERROR]);
}
$printer = self::list('',$params['printer_sn']); $printer = self::list('',$params['printer_sn']);
if ($printer['total'] > 0) { if ($printer['total'] > 0) {
throw new GoodsException( throw new GoodsException(
['cus' => GoodsException::PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]] ['cus' => GoodsException::PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
...@@ -87,8 +90,11 @@ class OtaService ...@@ -87,8 +90,11 @@ class OtaService
} }
//检查标签打印机是否已存在 -- 打印机已被(商家名称)绑定 //检查标签打印机是否已存在 -- 打印机已被(商家名称)绑定
if(isset($params['label_printer_sn']) && $params['label_printer_sn']) { if(isset($params['label_printer_sn']) && $params['label_printer_sn']) {
$printer = self::list('','', '', $params['label_printer_sn']);
if (!(new OtaValidate())->is_label_printer_sn($params['label_printer_sn'])) {
throw new GoodsException(['cus' => GoodsException::PRINTER_SN_ERROR]);
}
$printer = self::list('','', '', $params['label_printer_sn']);
if ($printer['total'] > 0) { if ($printer['total'] > 0) {
throw new GoodsException( throw new GoodsException(
['cus' => GoodsException::LABEL_PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]] ['cus' => GoodsException::LABEL_PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
...@@ -145,13 +151,23 @@ class OtaService ...@@ -145,13 +151,23 @@ class OtaService
return self::update(['ota_id'=>$otaId,'status'=>Ota::STATUS_DELETE]); return self::update(['ota_id'=>$otaId,'status'=>Ota::STATUS_DELETE]);
} }
/**
* 取消删除供应商
* @param $otaId
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function unDeleteOne($otaId)
{
return self::update(['ota_id'=>$otaId,'status'=>Ota::STATUS_NORMAL]);
}
/** /**
* 更新供应商信息 * 更新供应商信息
* @param $params * @param $params
* @return \Api\PhpUtils\Mysql\MysqlBase * @return \Api\PhpUtils\Mysql\MysqlBase
* @throws GoodsException * @throws GoodsException
*/ */
public static function update($params) public static function update($params, $canUnBind = false)
{ {
if(empty($params['ota_id'])) { if(empty($params['ota_id'])) {
...@@ -166,24 +182,53 @@ class OtaService ...@@ -166,24 +182,53 @@ class OtaService
//检查打印机是否已存在 -- 打印机已被(商家名称)绑定 //检查打印机是否已存在 -- 打印机已被(商家名称)绑定
if(isset($params['printer_sn']) && $params['printer_sn']) { if(isset($params['printer_sn']) && $params['printer_sn'] && $otaDetail['printer_sn'] != $params['printer_sn']) {
$printer = self::list('',$params['printer_sn']);
if ((new OtaValidate())->is_label_printer_sn($params['printer_sn'])) {
throw new GoodsException(['cus' => GoodsException::PRINTER_SN_ERROR]);
}
$printer = self::list('',$params['printer_sn']);
if ($printer['total'] > 0) { if ($printer['total'] > 0) {
throw new GoodsException( throw new GoodsException(
['cus' => GoodsException::PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]] ['cus' => GoodsException::PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
); );
} }
try {
$FeiPrinter = PrinterFactory::getPrinter('Fei');
$FeiPrinter->addPrinter([
'printer_sn' => $params['printer_sn'],
'printer_key' => $params['printer_key'],
'ota_name' => $params['ota_name'],
]);
} catch (\Exception $e) {
throw new GoodsException(['cus' => GoodsException::PRINTER_BIND_ERROR,'data'=>[$e->getMessage()]]);
}
} }
//检查标签打印机是否已存在 -- 打印机已被(商家名称)绑定 //检查标签打印机是否已存在 -- 打印机已被(商家名称)绑定
if(isset($params['label_printer_sn']) && $params['label_printer_sn']) { if(isset($params['label_printer_sn']) && $params['label_printer_sn'] && $otaDetail['label_printer_sn'] != $params['label_printer_sn']) {
$printer = self::list('','', '', $params['label_printer_sn']);
if (!(new OtaValidate())->is_label_printer_sn($params['label_printer_sn'])) {
throw new GoodsException(['cus' => GoodsException::PRINTER_SN_ERROR]);
}
$printer = self::list('','', '', $params['label_printer_sn']);
if ($printer['total'] > 0) { if ($printer['total'] > 0) {
throw new GoodsException( throw new GoodsException(
['cus' => GoodsException::LABEL_PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]] ['cus' => GoodsException::LABEL_PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
); );
} }
try {
$FeiPrinter = PrinterFactory::getPrinter('Fei');
$FeiPrinter->addPrinter([
'printer_sn' => $params['label_printer_sn'],
'printer_key' => $params['label_printer_key'],
'ota_name' => $params['ota_name'],
]);
} catch (\Exception $e) {
throw new GoodsException(['cus' => GoodsException::PRINTER_BIND_ERROR,'data'=>[$e->getMessage()]]);
}
} }
...@@ -199,6 +244,15 @@ class OtaService ...@@ -199,6 +244,15 @@ class OtaService
isset($params['address']) && $data['address'] = $params['address']; isset($params['address']) && $data['address'] = $params['address'];
isset($params['status']) && $data['status'] = $params['status']; isset($params['status']) && $data['status'] = $params['status'];
// 解绑
if ($canUnBind && !empty($otaDetail['printer_sn']) && empty($params['printer_sn']) && empty($params['printer_key'])) {
$data['printer_sn'] = $data['printer_key'] = '';
}
if ($canUnBind && !empty($otaDetail['label_printer_sn']) && empty($params['label_printer_sn']) && empty($params['label_printer_key'])) {
$data['label_printer_sn'] = $data['label_printer_key'] = '';
}
return Ota::update( return Ota::update(
$data, $data,
['ota_id'=>$params['ota_id']] ['ota_id'=>$params['ota_id']]
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
namespace App\Services\user; namespace App\Services\user;
use Api\PhpUtils\Mon\MonUtil;
use App\Models\user\mysql\UserWechatBind; use App\Models\user\mysql\UserWechatBind;
use Api\PhpUtils\Http\Request; use Api\PhpUtils\Http\Request;
use App\Services\user\Weixin\WxBizDataCrypt;; use App\Services\user\Weixin\WxBizDataCrypt;;
use App\Exception\BaseException; use App\Exception\BaseException;
use App\Exception\custom\UserException; use App\Exception\custom\UserException;
use Api\PhpUtils\Validate\Validate; use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen; use Api\PhpServices\Idgen\Idgen;
use Api\PhpUtils\Redis\RedisUtil; use Api\PhpUtils\Redis\RedisUtil;
...@@ -64,24 +64,18 @@ class UserService ...@@ -64,24 +64,18 @@ class UserService
]; ];
$response = (new Request())->post($loginUrl, $params); $response = (new Request())->post($loginUrl, $params);
if ($response['code'] == 0) {
$response = $response['response'];
}
$end = microtime(true); if (empty($response) || array_key_exists('errcode', $response)) {
$totalTime = round(($end - $begin), 4) * 1000; //throw new \Exception('获取openid失败:' . $response['errcode']);
if ($response['code'] == 0) { FileLog::error("wechatLogin:获取openid失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
$response = $response['response']; throw new UserException(['cus' => 1]);
} }
//检查系统是已注册
//mon打点 $openid = !empty($response['openid']) ? $response['openid'] : '';
$env = \Yaf\Application::app()->environ() ?? "dev"; //}
MonUtil::proxyMon($loginUrl, $response['code'], 'weixin_'.$env, $totalTime);
if (empty($response) || array_key_exists('errcode', $response)) {
//throw new \Exception('获取openid失败:' . $response['errcode']);
FileLog::error("wechatLogin:获取openid失败", json_encode($params, JSON_UNESCAPED_UNICODE), '', 'jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 1]);
}
//检查系统是已注册
$openid = !empty($response['openid']) ? $response['openid'] : '';
$user = UserWechatBind::getRecordMaster(['openid' => $openid]); $user = UserWechatBind::getRecordMaster(['openid' => $openid]);
......
...@@ -108,6 +108,9 @@ class FeiPrinter extends \Api\PhpServices\Printer\Printer ...@@ -108,6 +108,9 @@ class FeiPrinter extends \Api\PhpServices\Printer\Printer
if (is_array($res['response']['data']['ok']) && count($res['response']['data']['ok']) > 0) { if (is_array($res['response']['data']['ok']) && count($res['response']['data']['ok']) > 0) {
return true; return true;
} }
if (strpos($res['response']['data']['no'][0], '已被添加过')) {
return true;
}
throw new \Exception($res['response']['data']['no'][0]); throw new \Exception($res['response']['data']['no'][0]);
} }
throw new \Exception($res['response']['msg']); throw new \Exception($res['response']['msg']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment