Commit 61084a8e authored by pengfei's avatar pengfei

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

parents fe706b92 c49394d4
...@@ -16,6 +16,8 @@ class GoodsException extends BaseException ...@@ -16,6 +16,8 @@ class GoodsException extends BaseException
const OTA_NOT_EXIST = 38; const OTA_NOT_EXIST = 38;
const RULE_LIMIT_ERROR = 50; const RULE_LIMIT_ERROR = 50;
const NOT_FIND_MARKETING = 51; const NOT_FIND_MARKETING = 51;
const LABEL_PRINTER_ALREADY_EXIST = 53;
const PRINTER_BIND_ERROR = 54;
protected $cus = [ protected $cus = [
0 => '商品创建失败,请稍后重试', 0 => '商品创建失败,请稍后重试',
...@@ -71,5 +73,7 @@ class GoodsException extends BaseException ...@@ -71,5 +73,7 @@ class GoodsException extends BaseException
self::RULE_LIMIT_ERROR => '单人可买上限填写错误', self::RULE_LIMIT_ERROR => '单人可买上限填写错误',
self::NOT_FIND_MARKETING => '找不到活动', self::NOT_FIND_MARKETING => '找不到活动',
52 => '过期时间不得小于等于上架开始时间', 52 => '过期时间不得小于等于上架开始时间',
self::LABEL_PRINTER_ALREADY_EXIST => '标签打印机已被%s绑定',
self::PRINTER_BIND_ERROR => '打印机绑定失败:%s',
]; ];
} }
\ No newline at end of file
...@@ -14,6 +14,10 @@ class OtaValidate extends \Validate\BaseValidate ...@@ -14,6 +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',
'location' => 'require',
'longitude' => 'require',
'latitude' => 'require',
'offset' => 'egt:0', 'offset' => 'egt:0',
'limit' => 'elt:100', 'limit' => 'elt:100',
]; ];
...@@ -22,6 +26,10 @@ class OtaValidate extends \Validate\BaseValidate ...@@ -22,6 +26,10 @@ class OtaValidate extends \Validate\BaseValidate
protected $message = [ protected $message = [
"ota_name" => "供应商名称不能为空", "ota_name" => "供应商名称不能为空",
"ota_id" => "ota_id不能为空", "ota_id" => "ota_id不能为空",
"address" => "详细地址不能为空",
"location" => "高德地图详细地址不能为空",
"longitude" => "经度不能为空",
"latitude" => "纬度不能为空",
"offset" => "偏移量不能小于0", "offset" => "偏移量不能小于0",
"limit" => "单次不能大于100条", "limit" => "单次不能大于100条",
]; ];
...@@ -34,7 +42,7 @@ class OtaValidate extends \Validate\BaseValidate ...@@ -34,7 +42,7 @@ class OtaValidate extends \Validate\BaseValidate
public function sceneAdd() public function sceneAdd()
{ {
return $this->only(['ota_name']); return $this->only(['ota_name', 'address','longitude','latitude', 'location']);
} }
public function sceneDelete() public function sceneDelete()
{ {
...@@ -43,7 +51,7 @@ class OtaValidate extends \Validate\BaseValidate ...@@ -43,7 +51,7 @@ class OtaValidate extends \Validate\BaseValidate
public function sceneUpdate() public function sceneUpdate()
{ {
return $this->only(['ota_id']); return $this->only(['ota_id', 'ota_name', 'address','longitude','latitude', 'location']);
} }
public function sceneListByIds() public function sceneListByIds()
{ {
......
...@@ -22,9 +22,11 @@ class OtaController extends Base ...@@ -22,9 +22,11 @@ class OtaController extends Base
$name = $this->params['ota_name'] ?? ''; $name = $this->params['ota_name'] ?? '';
$printerSn = $this->params['printer_sn'] ?? ''; $printerSn = $this->params['printer_sn'] ?? '';
$printerKey = $this->params['printer_key'] ?? ''; $printerKey = $this->params['printer_key'] ?? '';
$labelPrinterSn = $this->params['label_printer_sn'] ?? '';
$labelPrinterKey = $this->params['label_printer_key'] ?? '';
$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, $offset, $limit); $res = OtaService::list($name, $printerSn, $printerKey,$labelPrinterSn, $labelPrinterKey, $offset, $limit);
$this->success(['result' => $res]); $this->success(['result' => $res]);
} }
......
...@@ -4,10 +4,11 @@ namespace App\Services\goods; ...@@ -4,10 +4,11 @@ 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;
class OtaService class OtaService
{ {
const COLUMNS = ['ota_id','ota_name','printer_sn','printer_key','label_printer_sn','label_printer_key']; const COLUMNS = ['ota_id','ota_name','printer_sn','printer_key','label_printer_sn','label_printer_key', 'longitude', 'latitude', 'location', 'address', 'status'];
/** /**
* 获取供应商列表(op 后台) * 获取供应商列表(op 后台)
* @param string $otaName * @param string $otaName
...@@ -17,13 +18,15 @@ class OtaService ...@@ -17,13 +18,15 @@ 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='',$offset=0,$limit=20) public static function list($otaName='',$printerSN='',$printerKey='', $labelPrinterSN='',$labelPrinterKey='',$offset=0,$limit=20)
{ {
$otaName && $where['ota_name'] = $otaName; $otaName && $where['ota_name'] = $otaName;
$printerSN && $where["printer_sn"] = $printerSN; $printerSN && $where["printer_sn"] = $printerSN;
$printerKey && $where['printer_key'] = $printerKey; $printerKey && $where['printer_key'] = $printerKey;
$labelPrinterSN && $where["label_printer_sn"] = $labelPrinterSN;
$labelPrinterKey && $where['label_printer_key'] = $labelPrinterKey;
$where['status'] = Ota::STATUS_NORMAL; // $where['status'] = Ota::STATUS_NORMAL;
$where['ORDER'] = ['ota_id' => 'DESC']; $where['ORDER'] = ['ota_id' => 'DESC'];
$where['LIMIT'] = [$offset, $limit]; $where['LIMIT'] = [$offset, $limit];
...@@ -82,10 +85,52 @@ class OtaService ...@@ -82,10 +85,52 @@ class OtaService
); );
} }
} }
//检查标签打印机是否已存在 -- 打印机已被(商家名称)绑定
if(isset($params['label_printer_sn']) && $params['label_printer_sn']) {
$printer = self::list('','', '', $params['label_printer_sn']);
if ($printer['total'] > 0) {
throw new GoodsException(
['cus' => GoodsException::LABEL_PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
);
}
}
try {
if(isset($params['printer_sn']) && $params['printer_sn']) {
$FeiPrinter = PrinterFactory::getPrinter('Fei');
$FeiPrinter->addPrinter([
'printer_sn' => $params['printer_sn'],
'printer_key' => $params['printer_key'],
'ota_name' => $params['ota_name'],
]);
}
if(isset($params['label_printer_sn']) && $params['label_printer_sn']) {
$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()]]
);
}
$data['ota_name'] = $params['ota_name']; $data['ota_name'] = $params['ota_name'];
$data['printer_sn'] = $params['printer_sn'] ?? ''; $data['printer_sn'] = $params['printer_sn'] ?? '';
$data['printer_key'] = $params['printer_key'] ?? ''; $data['printer_key'] = $params['printer_key'] ?? '';
$data['label_printer_sn'] = $params['label_printer_sn'] ?? '';
$data['label_printer_key'] = $params['label_printer_key'] ?? '';
$data['longitude'] = $params['longitude'];
$data['latitude'] = $params['latitude'];
$data['location'] = $params['location'];
$data['address'] = $params['address'];
return Ota::insert($data); return Ota::insert($data);
} }
...@@ -108,13 +153,40 @@ class OtaService ...@@ -108,13 +153,40 @@ class OtaService
*/ */
public static function update($params) public static function update($params)
{ {
if(empty($params['ota_id'])) { if(empty($params['ota_id'])) {
throw new GoodsException(['cus' => GoodsException::EMPTY_OTA_ID]); throw new GoodsException(['cus' => GoodsException::EMPTY_OTA_ID]);
} }
$otaDetail = self::detail($params['ota_id']);
//检查供应商是否存在 //检查供应商是否存在
if (empty(self::detail($params['ota_id']))) { if (empty($otaDetail)) {
throw new GoodsException(['cus' => GoodsException::OTA_NOT_EXIST]); throw new GoodsException(['cus' => GoodsException::OTA_NOT_EXIST]);
} }
//检查打印机是否已存在 -- 打印机已被(商家名称)绑定
if(isset($params['printer_sn']) && $params['printer_sn']) {
$printer = self::list('',$params['printer_sn']);
if ($printer['total'] > 0) {
throw new GoodsException(
['cus' => GoodsException::PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
);
}
}
//检查标签打印机是否已存在 -- 打印机已被(商家名称)绑定
if(isset($params['label_printer_sn']) && $params['label_printer_sn']) {
$printer = self::list('','', '', $params['label_printer_sn']);
if ($printer['total'] > 0) {
throw new GoodsException(
['cus' => GoodsException::LABEL_PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
);
}
}
$data = []; $data = [];
isset($params['ota_name']) && $data['ota_name'] = $params['ota_name']; isset($params['ota_name']) && $data['ota_name'] = $params['ota_name'];
isset($params['printer_sn']) && $data['printer_sn'] = $params['printer_sn']; isset($params['printer_sn']) && $data['printer_sn'] = $params['printer_sn'];
......
...@@ -27,6 +27,8 @@ class UserService ...@@ -27,6 +27,8 @@ class UserService
{ {
$code = !empty($params['code']) ? $params['code'] : '';//小程序授权code $code = !empty($params['code']) ? $params['code'] : '';//小程序授权code
$openid = !empty($params['openid']) ? $params['openid'] : '';//小程序授权code $openid = !empty($params['openid']) ? $params['openid'] : '';//小程序授权code
$inviteUserId = !empty($params['invite_user_id']) ? intval($params['invite_user_id']) : 0;//邀请用户id
$activityType = !empty($params['activity_type']) ? intval($params['activity_type']) : 0;//活动类型
if (empty($code) && empty($openid)) { if (empty($code) && empty($openid)) {
FileLog::error("wechatLogin:获取参数为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com'); FileLog::error("wechatLogin:获取参数为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 0]); throw new UserException(['cus' => 0]);
...@@ -83,6 +85,8 @@ class UserService ...@@ -83,6 +85,8 @@ class UserService
'openid' => !empty($response['openid']) ? $response['openid'] : '', 'openid' => !empty($response['openid']) ? $response['openid'] : '',
'union_id' => !empty($response['unionid']) ? $response['unionid'] : '', 'union_id' => !empty($response['unionid']) ? $response['unionid'] : '',
'session_key' => !empty($response['session_key']) ? $response['session_key'] : '', //默认7200有效期 'session_key' => !empty($response['session_key']) ? $response['session_key'] : '', //默认7200有效期
'invite_user_id' => $inviteUserId,
'activity_type' => $activityType,
'create_time' => date("Y-m-d H:i:s") 'create_time' => date("Y-m-d H:i:s")
]; ];
......
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