Commit db64f257 authored by suntengda's avatar suntengda

update 供应商相关接口

parent 5f68b9f1
...@@ -40,7 +40,7 @@ class BaseException extends \Exception ...@@ -40,7 +40,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 = $this->cus[$cus_code]; $this->msg = isset($params['data']) ? vsprintf($this->cus[$cus_code],$params['data']) : $this->cus[$cus_code];
} }
} }
......
...@@ -10,6 +10,11 @@ class GoodsException extends BaseException ...@@ -10,6 +10,11 @@ class GoodsException extends BaseException
{ {
protected $base_code = Code::GOODS; protected $base_code = Code::GOODS;
const OTA_ALREADY_EXIST = 35;
const PRINTER_ALREADY_EXIST = 36;
const EMPTY_OTA_ID = 37;
const OTA_NOT_EXIST = 38;
protected $cus = [ protected $cus = [
0 => '商品创建失败,请稍后重试', 0 => '商品创建失败,请稍后重试',
1 => '店铺ID创建失败', 1 => '店铺ID创建失败',
...@@ -46,5 +51,9 @@ class GoodsException extends BaseException ...@@ -46,5 +51,9 @@ class GoodsException extends BaseException
32 => '当前商品已下单数量不足', 32 => '当前商品已下单数量不足',
33 => '售价不能为0', 33 => '售价不能为0',
34 => '售价不能大于5万元', 34 => '售价不能大于5万元',
self::OTA_ALREADY_EXIST => '供应商已存在',
self::PRINTER_ALREADY_EXIST => '打印机已被%s绑定',
self::EMPTY_OTA_ID => '供应商id为空',
self::OTA_NOT_EXIST => '供应商不存在',
]; ];
} }
\ No newline at end of file
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
use App\Base\Base; use App\Base\Base;
use App\Services\goods\OtaService; use App\Services\goods\OtaService;
use \Validate\Ota\getBindListValidate;
use Validate\otaValidate; use Validate\otaValidate;
class OtaController extends Base class OtaController extends Base
...@@ -62,12 +61,7 @@ class OtaController extends Base ...@@ -62,12 +61,7 @@ class OtaController extends Base
public function updateAction() public function updateAction()
{ {
(new otaValidate())->scene('update')->validate(); (new otaValidate())->scene('update')->validate();
$data = []; $res = OtaService::update($this->params);
$this->params['ota_name'] && $data['ota_name'] = $this->params['ota_name'];
$this->params['printer_sn'] && $data['printer_sn'] = $this->params['printer_sn'];
$this->params['printer_key'] && $data['printer_key'] = $this->params['printer_key'];
$res = $data ? OtaService::update($this->params['ota_id'], $data) : true;
$this->success(['status' => $res ? 'success' : 'failed']); $this->success(['status' => $res ? 'success' : 'failed']);
} }
......
<?php
/**
* Author : Tengda
* Date : 2021/7/29
* Time : 11:12 上午
*/
use App\Base\Base;
use App\Services\marketing\TakePlaceService;
use Validate\TakePlaceValidate;
class TakeplaceController extends Base
{
/**
* 获取自提点列表
* http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=71671761
* @throws \App\Exception\custom\ParamException
*/
public function listAction()
{
(new TakePlaceValidate())->scene('list')->validate();
$keywords = $this->params['keywords'] ?? '';
$offset = $this->params['offset'] ?? 0;
$limit = $this->params['limit'] ?? 20;
$res = TakePlaceService::searchList($keywords,$offset,$limit);
$this->success(['data'=>$res]);
}
/**
* 添加自提点
* http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=71671759
* @throws \App\Exception\custom\ParamException
*/
public function addAction()
{
(new takePlaceValidate())->scene('add')->validate();
$res = TakePlaceService::add($this->params);
$this->success(['status'=>$res ? 'success' : 'failed']);
}
/**
* 删除自提点
* @throws \App\Exception\custom\ParamException
*/
public function deleteAction()
{
(new takePlaceValidate())->scene('delete')->validate();
$res = TakePlaceService::delete($this->params['take_place_id']);
$this->success(['status'=>$res ? 'success' : 'failed']);
}
/**
* 获取活动绑定的自提点列表
* @throws \App\Exception\custom\ParamException
*/
public function get_bind_listAction()
{
(new takePlaceValidate())->scene('bindList')->validate();
$marketingPindanId = $this->params['marketing_pindan_id'];
$offset = $this->params['offset'] ?? 0;
$limit = $this->params['limit'] ?? 20;
$data = TakePlaceService::getPindanTakePlaceList($marketingPindanId,$offset,$limit);
$this->success(['data'=>$data]);
}
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Services\goods; namespace App\Services\goods;
use App\Exception\custom\GoodsException;
use App\Models\goods\mysql\Ota; use App\Models\goods\mysql\Ota;
class OtaService class OtaService
...@@ -40,16 +41,30 @@ class OtaService ...@@ -40,16 +41,30 @@ class OtaService
*/ */
public static function detail($OtaId) public static function detail($OtaId)
{ {
return Ota::get(self::COLUMNS,['id'=>$OtaId]); return Ota::get(self::COLUMNS,['ota_id'=>$OtaId]);
} }
/**
* 添加供应商
* @param $params
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws GoodsException
*/
public static function add($params) public static function add($params)
{ {
//检查供应商是否已存在
if (self::list($params['ota_name'])['total'] > 0) {
throw new GoodsException(['cus' => GoodsException::OTA_ALREADY_EXIST]);
}
//@todo 检查商家是否已存在 -- 该商家已存在 //检查打印机是否已存在 -- 打印机已被(商家名称)绑定
$printer = self::list('',$params['printer_sn']);
//@todo 检查打印机是否已存在 -- 打印机已被(商家名称)绑定 if ($printer['total'] > 0) {
throw new GoodsException(
['cus' => GoodsException::PRINTER_ALREADY_EXIST,'data'=>[$printer['list'][0]['ota_name']]]
);
}
$data['ota_name'] = $params['ota_name']; $data['ota_name'] = $params['ota_name'];
$data['printer_sn'] = $params['printer_sn']; $data['printer_sn'] = $params['printer_sn'];
...@@ -59,7 +74,7 @@ class OtaService ...@@ -59,7 +74,7 @@ class OtaService
} }
/** /**
* 删除商家 * 删除供应商
* @param $otaId * @param $otaId
* @return \Api\PhpUtils\Mysql\MysqlBase * @return \Api\PhpUtils\Mysql\MysqlBase
*/ */
...@@ -72,16 +87,28 @@ class OtaService ...@@ -72,16 +87,28 @@ class OtaService
} }
/** /**
* @param $otaId * 更新供应商信息
* @param $data * @param $params
* @return \Api\PhpUtils\Mysql\MysqlBase * @return \Api\PhpUtils\Mysql\MysqlBase
* @throws GoodsException
*/ */
public static function update($otaId,$data) public static function update($params)
{ {
//@todo 检查字段是否匹配 if(empty($params['ota_id'])) {
throw new GoodsException(['cus' => GoodsException::EMPTY_OTA_ID]);
}
//检查供应商是否存在
if (empty(self::detail($params['ota_id']))) {
throw new GoodsException(['cus' => GoodsException::OTA_NOT_EXIST]);
}
$data = [];
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'];
return Ota::update( return Ota::update(
$data, $data,
['ota_id'=>$otaId] ['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