Commit 85363ed9 authored by pengfei's avatar pengfei

Merge remote-tracking branch 'origin/test' into test

# Conflicts:
#	application/services/user/UserService.php
parents d10a3ead f8a5231d
......@@ -18,6 +18,7 @@ class GoodsException extends BaseException
const NOT_FIND_MARKETING = 51;
const LABEL_PRINTER_ALREADY_EXIST = 53;
const PRINTER_BIND_ERROR = 54;
const PRINTER_SN_ERROR = 55;
protected $cus = [
0 => '商品创建失败,请稍后重试',
......@@ -75,5 +76,6 @@ class GoodsException extends BaseException
52 => '过期时间不得小于等于上架开始时间',
self::LABEL_PRINTER_ALREADY_EXIST => '标签打印机已被%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
return $this->only(['ota_id']);
}
public function sceneUndelete()
{
return $this->only(['ota_id']);
}
public function sceneUpdate()
{
return $this->only(['ota_id', 'ota_name', 'address','longitude','latitude', 'location']);
......@@ -57,4 +62,12 @@ class OtaValidate extends \Validate\BaseValidate
{
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
......@@ -339,4 +339,14 @@ class GoodsController extends Base
$res = GoodsService::getOtaInfoByGoodsSkuIds($this->params);
$this->success(["result" => $res]);
}
/**
* 拼单商品快照批量获取
* @throws Exception
*/
public function goods_snapshotsAction()
{
$res = GoodsSnapshotsService::goodsSnapshots($this->params);
$this->success(["result" => $res]);
}
}
\ No newline at end of file
......@@ -69,6 +69,18 @@ class OtaController extends Base
$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']);
}
/**
* 更新供应商
......
......@@ -3,6 +3,8 @@
namespace App\Services\goods;
use Api\PhpUtils\Common\GoodsSkuId;
use App\Models\goods\mysql\GoodsSnapshot;
use App\Models\goods\mysql\PindanGoodsSnapshot;
class GoodsSnapshotsService
......@@ -32,4 +34,42 @@ class GoodsSnapshotsService
}
return $pindanGoodsSnapshot;
}
/**
* 批量支持商品
* @param $params
* @return array
*/
public static function goodsSnapshots($params)
{
$str = empty($params["snapshots_str"]) ? "" : $params["snapshots_str"];
$snapshot = [];
if (!empty($str)) {
$paramsArr = json_decode($str, true);
if (!empty($paramsArr)) {
foreach ($paramsArr as $param) {
if (isset($param["goods_sku_id"]) || isset($param["goods_version"])) {
$goodsSkuIdParams = GoodsSkuId::getGoodsSkuIdParams($param["goods_sku_id"]);
$key = $param["goods_sku_id"]."_".$param["goods_version"];
if ($goodsSkuIdParams["table_tag"] == GoodsSkuId::TABLE_TAG_PINDAN) {
$snapshot[$key] = PindanGoodsSnapshot::getRecord([
"goods_sku_id" => $param["goods_sku_id"],
"goods_version" => $param["goods_version"]
]);
} else {
$snapshot[$key] = GoodsSnapshot::getRecord([
"goods_sku_id" => $param["goods_sku_id"],
"goods_version" => $param["goods_version"]
]);
}
if (!empty($snapshot[$key]["desc_pic_url"])) {
$ksyun = GoodsService::getUrlList($snapshot[$key]["desc_pic_url"]);
$snapshot[$key]["desc_pic_url_list"] = $ksyun;
}
}
}
}
}
return $snapshot;
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ namespace App\Services\goods;
use App\Exception\custom\GoodsException;
use App\Models\goods\mysql\Ota;
use Api\PhpServices\Printer\PrinterFactory;
use Validate\OtaValidate;
class OtaService
{
......@@ -77,8 +78,10 @@ class OtaService
//检查打印机是否已存在 -- 打印机已被(商家名称)绑定
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']);
if ($printer['total'] > 0) {
throw new GoodsException(
['cus' => GoodsException::PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
......@@ -87,8 +90,11 @@ class OtaService
}
//检查标签打印机是否已存在 -- 打印机已被(商家名称)绑定
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) {
throw new GoodsException(
['cus' => GoodsException::LABEL_PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
......@@ -145,6 +151,16 @@ class OtaService
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
......@@ -166,24 +182,53 @@ class OtaService
//检查打印机是否已存在 -- 打印机已被(商家名称)绑定
if(isset($params['printer_sn']) && $params['printer_sn']) {
$printer = self::list('',$params['printer_sn']);
if(isset($params['printer_sn']) && $params['printer_sn'] && $otaDetail['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']);
if ($printer['total'] > 0) {
throw new GoodsException(
['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']) {
$printer = self::list('','', '', $params['label_printer_sn']);
if(isset($params['label_printer_sn']) && $params['label_printer_sn'] && $otaDetail['label_printer_sn'] != $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) {
throw new GoodsException(
['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()]]);
}
}
......@@ -191,8 +236,23 @@ class OtaService
isset($params['ota_name']) && $data['ota_name'] = $params['ota_name'];
isset($params['printer_sn']) && $data['printer_sn'] = $params['printer_sn'];
isset($params['printer_key']) && $data['printer_key'] = $params['printer_key'];
isset($params['label_printer_sn']) && $data['label_printer_sn'] = $params['label_printer_sn'];
isset($params['label_printer_key']) && $data['label_printer_key'] = $params['label_printer_key'];
isset($params['longitude']) && $data['longitude'] = $params['longitude'];
isset($params['latitude']) && $data['latitude'] = $params['latitude'];
isset($params['location']) && $data['location'] = $params['location'];
isset($params['address']) && $data['address'] = $params['address'];
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(
$data,
['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