Commit e06effd8 authored by 孟维甫's avatar 孟维甫

Merge branch 'feature_ota_manage' into 'test'

Feature ota manage

See merge request bp/goods!47
parents 68a26f4c 0df0d809
...@@ -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
...@@ -49,6 +49,11 @@ class OtaValidate extends \Validate\BaseValidate ...@@ -49,6 +49,11 @@ class OtaValidate extends \Validate\BaseValidate
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', 'address','longitude','latitude', 'location']);
...@@ -57,4 +62,12 @@ class OtaValidate extends \Validate\BaseValidate ...@@ -57,4 +62,12 @@ class OtaValidate extends \Validate\BaseValidate
{ {
return $this->only(['ota_id']); return $this->only(['ota_id']);
} }
protected function is_label_printer_sn($value){
if( substr($value, 3, 1) != 2 ){
return false;
}
return true;
}
} }
\ No newline at end of file
...@@ -69,6 +69,18 @@ class OtaController extends Base ...@@ -69,6 +69,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']);
}
/** /**
* 更新供应商 * 更新供应商
......
...@@ -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
{ {
...@@ -145,6 +146,16 @@ class OtaService ...@@ -145,6 +146,16 @@ 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
...@@ -166,24 +177,53 @@ class OtaService ...@@ -166,24 +177,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['label_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 +239,15 @@ class OtaService ...@@ -199,6 +239,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 (!empty($otaDetail['printer_sn']) && empty($params['printer_sn']) && empty($params['printer_key'])) {
$data['printer_sn'] = $params['printer_key'] = '';
}
if (!empty($otaDetail['label_printer_sn']) && empty($params['label_printer_sn']) && empty($params['label_printer_key'])) {
$data['label_printer_sn'] = $params['label_printer_key'] = '';
}
return Ota::update( return Ota::update(
$data, $data,
['ota_id'=>$params['ota_id']] ['ota_id'=>$params['ota_id']]
......
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