Commit cd2be1bc authored by luhongguang's avatar luhongguang

update:处理冲突

parents afd3967c 2167735e
......@@ -10,6 +10,9 @@ class MarketingException extends BaseException
{
protected $base_code = Code::MARKETING;
const LIFE_ACCOUNT_NO_EXIST = 16;
const RELATION_ALREADY_EXIST = 17;
protected $cus = [
0 => '活动名称不能为空',
1 => '活动名称不能大于50',
......@@ -27,6 +30,8 @@ class MarketingException extends BaseException
13 => '商品在其他互动已勾选',
14 => '开始时间不能大于等于结束时间',
15 => '分润比例不能大于50%',
16 => '当前填写的拼单活动名称已经存在',
self::LIFE_ACCOUNT_NO_EXIST => '生活号不存在',
self::RELATION_ALREADY_EXIST => '该关联记录已存在',
18 => '当前填写的拼单活动名称已经存在',
];
}
\ No newline at end of file
<?php
namespace Validate;
/**
* Class addValidate
*
* @package Validate
*/
class OtaValidate extends \Validate\BaseValidate
{
protected $rule = [
'ota_name' => 'require',
'ota_id' => 'require',
'offset' => 'egt:0',
'limit' => 'elt:100',
];
protected $message = [
"ota_name" => "供应商名称不能为空",
"ota_id" => "ota_id不能为空",
"offset" => "偏移量不能小于0",
"limit" => "单次不能大于100条",
];
public function sceneList()
{
return $this->only(['offset','limit']);
}
public function sceneAdd()
{
return $this->only(['ota_name']);
}
public function sceneDelete()
{
return $this->only(['ota_id']);
}
public function sceneUpdate()
{
return $this->only(['ota_id']);
}
}
\ No newline at end of file
<?php
namespace Validate;
/**
* Class addValidate
*
* @package Validate
*/
class TakePlaceValidate extends \Validate\BaseValidate
{
protected $rule = [
'take_place_id' => 'require',
'name' => 'require',
'address' => 'require',
'longitude' => 'require',
'latitude' => 'require',
'province' => 'require',
'city' => 'require',
'area' => 'require',
'offset' => 'egt:0',
'limit' => 'elt:100',
];
protected $message = [
"take_place_id" => "take_place_id不能为空",
"marketing_pindan_id" => "marketing_pindan_id不能为空",
"name" => "自提点名称不能为空",
"address" => "详细地址不能为空",
"longitude" => "经度不能为空",
"latitude" => "纬度不能为空",
"province" => "省不能为空",
"city" => "市不能为空",
"area" => "区不能为空",
"offset" => "偏移量不能小于0",
"limit" => "单次不能大于100条",
];
public function sceneList()
{
return $this->only(['offset','limit']);
}
public function sceneAdd()
{
return $this->only(['name','address','longitude','latitude','province','city','area']);
}
public function sceneDelete()
{
return $this->only(['take_place_id']);
}
public function sceneBindList()
{
return $this->append(['marketing_pindan_id' => 'require'])->only(['marketing_pindan_id','offset','limit']);
}
}
\ No newline at end of file
<?php
namespace App\Models\goods\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
/**
* 供应商
* Class Ota
* @package App\Models\goods\mysql
*/
class Ota extends MysqlBase
{
const TABLE_NAME = 'ota';
const CONFIG_INDEX = 'goods';
const PRIMARY_KEY = 'id';
const STATUS_NORMAL = 0; // 正常
const STATUS_DELETE = 1; // 删除
}
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
/**
* 拼单活动和自提点关联
* Class MarketingTakePlace
* @package App\Models\marketing\mysql
*/
class MarketingTakePlace extends MysqlBase
{
const TABLE_NAME = 'marketing_take_place';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'marketing_take_place_id';
}
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
/**
* 自提点
* Class TakePlace
* @package App\Models\marketing\mysql
*/
class TakePlace extends MysqlBase
{
const TABLE_NAME = 'take_place';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'take_place_id';
const STATUS_NORMAL = 0; // 正常
const STATUS_DELETE = 1; // 删除
/**
* 获取
* @param $keywords
* @param int $offset
* @param int $limit
* @return mixed
*/
public static function searchList($keywords,$offset=0,$limit=20)
{
if($keywords) {
$where = [
'AND' => [
'OR' => [
'take_place_name[~]' => $keywords,
'contact_name[~]' => $keywords,
],
'is_delete' => TakePlace::STATUS_NORMAL,
],
];
}else {
$where = ['is_delete' => TakePlace::STATUS_NORMAL];
}
$where['ORDER'] = ['take_place_id' => 'DESC'];
$where['LIMIT'] = [$offset, $limit];
// $e = TakePlace::debug();
$res['list'] = self::select('*', $where);
$res['total'] = self::count('*', $where);
return $res;
}
}
<?php
/**
* Author : Tengda
* Date : 2021/7/29
* Time : 11:12 上午
*/
use App\Base\Base;
use App\Services\goods\OtaService;
use \Validate\Ota\getBindListValidate;
use Validate\otaValidate;
class OtaController extends Base
{
/**
* 供应商列表
*/
public function listAction()
{
(new otaValidate())->scene('list')->validate();
$name = $this->params['ota_name'] ?? '';
$printerSn = $this->params['printer_sn'] ?? '';
$printerKey = $this->params['printer_key'] ?? '';
$offset = $this->params['offset'] ?? 0;
$limit = $this->params['limit'] ?? 20;
$res = OtaService::list($name, $printerSn, $printerKey, $offset, $limit);
$this->success(['data' => $res]);
}
/**
* 添加供应商
* @throws \App\Exception\custom\ParamException
*/
public function addAction()
{
(new otaValidate())->scene('add')->validate();
$res = OtaService::add($this->params);
$this->success(['status' => $res ? 'success' : 'failed']);
}
/**
* 删除一个供应商
* @throws \App\Exception\custom\ParamException
*/
public function deleteAction()
{
(new otaValidate())->scene('delete')->validate();
$res = OtaService::deleteOne($this->params['ota_id']);
$this->success(['status' => $res ? 'success' : 'failed']);
}
/**
* 更新供应商
* @throws Exception
*/
public function updateAction()
{
(new otaValidate())->scene('update')->validate();
$data = [];
$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']);
}
}
\ No newline at end of file
<?php
/**
* Author : Tengda
* Date : 2021/7/29
* Time : 17:59 下午
*/
use App\Base\Base;
//use App\Services\marketing\SpellService;
//use \Validate\Spell\detailValidate;
class SpellController extends Base {
public function detailAction()
{
// (new detailValidate())->validate();
//
// $name = $this->params['name'] ?? '';
// $printerSn = $this->params['printer_sn'] ?? '';
// $printerKey = $this->params['printer_key'] ?? '';
// $offset = $this->params['offset'] ?? 0;
// $limit = $this->params['limit'] ?? 20;
// $res = TakePlaceService::list($name,$printerSn,$printerKey,$offset,$limit);
$data = [
'detail'=>[],
];
$this->success(['data'=>$data]);
}
public function listAction()
{
$data = [
'list'=>[
[
'uid'=>123,
'username'=>'aaa',
'avator'=>'aaaaaa.jpg',
'id'=>1,
'name'=>'一起拼一定赢',
'desc'=>'吃喝玩乐',
'create_time'=>'2021-07-29 20:03:08',
'sold_num'=>123,
'min_price'=>15,
'max_price'=>89,
],
[
'uid'=>234,
'username'=>'bbbbb',
'avator'=>'aaaaaa1.jpg',
'id'=>1,
'name'=>'俺是打款就',
'desc'=>'吃喝玩乐',
'create_time'=>'2021-07-29 20:03:08',
'sold_num'=>345,
'min_price'=>13,
'max_price'=>99,
]
],
'total'=>2
];
$this->success(['data'=>$data]);
}
}
\ No newline at end of file
<?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 getBindListAction()
{
(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
<?php
namespace App\Services\goods;
use App\Models\goods\mysql\Ota;
class OtaService
{
const COLUMNS = ['ota_id','ota_name','printer_sn','printer_key'];
/**
* 获取供应商列表(op 后台)
* @param string $otaName
* @param string $contacts
* @param string $phone
* @param int $offset
* @param int $limit
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function list($otaName='',$printerSN='',$printerKey='',$offset=0,$limit=20)
{
$otaName && $where['ota_name'] = $otaName;
$printerSN && $where["printer_sn"] = $printerSN;
$printerKey && $where['printer_key'] = $printerKey;
$where['status'] = Ota::STATUS_NORMAL;
$where['ORDER'] = ['ota_id' => 'DESC'];
$where['LIMIT'] = [$offset, $limit];
// $e = Ota::debug();
$res['list'] = Ota::select(self::COLUMNS, $where);
$res['total'] = Ota::count('*', $where);
return $res;
}
/**
* 获取某个ota详情
* @param $OtaId
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function detail($OtaId)
{
return Ota::get(self::COLUMNS,['id'=>$OtaId]);
}
public static function add($params)
{
//@todo 检查商家是否已存在 -- 该商家已存在
//@todo 检查打印机是否已存在 -- 打印机已被(商家名称)绑定
$data['ota_name'] = $params['ota_name'];
$data['printer_sn'] = $params['printer_sn'];
$data['printer_key'] = $params['printer_key'];
return Ota::insert($data);
}
/**
* 删除商家
* @param $otaId
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function deleteOne($otaId)
{
return Ota::update(
['is_delete'=>Ota::STATUS_DELETE],
['ota_id'=>$otaId]
);
}
/**
* @param $otaId
* @param $data
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function update($otaId,$data)
{
//@todo 检查字段是否匹配
return Ota::update(
$data,
['ota_id'=>$otaId]
);
}
}
\ No newline at end of file
......@@ -376,7 +376,7 @@ class MarketingService
if (!empty($marketing)) {
$marketingPindan = MarketingPindan::getRecord(["marketing_id" => $marketing["marketing_id"]]);
if (!empty($marketingPindan) && $publishLifeAccountId == $marketingPindan["publish_life_account_id"]) {
throw new MarketingException(['cus' => 16]);
throw new MarketingException(['cus' => 18]);
}
}
......
<?php
namespace App\Services\marketing;
use Api\PhpUtils\Http\Request;
use App\Models\marketing\mysql\MarketingTakePlace;
use App\Models\marketing\mysql\TakePlace;
use App\Exception\custom\MarketingException;
class TakePlaceService
{
const SELF_LIFE_ACCOUNT_ID = 123123;
/**
* 获取自提点列表(op 后台)
*
* 支持关键词(自提点名称/联系人)搜索
* @param string $keywords
* @param int $offset
* @param int $limit
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function searchList($keywords='',$offset=0,$limit=20)
{
return TakePlace::searchList($keywords, $offset, $limit);
}
/**
* 获取某个自提点详情
* 有删除自提点的情况,订单获取自提点详情时忽略自提点状态直接按id获取
* @param $takePlaceId
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function detail($takePlaceId)
{
return TakePlace::get('*',['take_place_id'=>$takePlaceId]);
}
/**
* 添加自提点
* @param $params
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws MarketingException
*/
public static function add($params)
{
//验证life_account_id
if(isset($params['life_account_id'])) {
$url = config('interface', 'merchant.lifeaccount.get_life_account_by_id');
$lifeAccountRes = (new Request())->get($url, ["life_account_id" => $params["life_account_id"]]);
if (empty($lifeAccountRes["response"]["result"])) {
throw new MarketingException(['cus' => MarketingException::LIFE_ACCOUNT_NO_EXIST]);
}
}
$data['life_account_id'] = $params['life_account_id'] ?? self::SELF_LIFE_ACCOUNT_ID;
$data['take_place_name'] = $params['name'];
$data['longitude'] = $params['longitude'];
$data['latitude'] = $params['latitude'];
$data['address'] = $params['address'];
$data['contact_name'] = $params['contact_name'] ?? '';
$data['phone'] = $params['phone'] ?? '';
$data['province'] = $params['province'];
$data['city'] = $params['city'];
$data['area'] = $params['area'];
return TakePlace::insert($data);
}
/**
* 删除自提点
* @param $takePlaceId
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function delete($takePlaceId)
{
return TakePlace::update(
['is_delete'=>TakePlace::STATUS_DELETE],
['take_place_id'=>$takePlaceId]
);
}
/**
* 给拼单活动绑定自提点
* @param $marketingPindanId
* @param $takePlaceId
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function bindPindanTakePlace($marketingPindanId,$takePlaceId)
{
$data = [
'marketing_pindan_id'=>$marketingPindanId,
'take_place_id'=>$takePlaceId,
];
//检查关联是否已存在
if(!empty(MarketingTakePlace::get('*',$data))) {
throw new MarketingException(['cus' => MarketingException::RELATION_ALREADY_EXIST]);
}
return MarketingTakePlace::insert($data);
}
/**
* 获取拼单活动绑定的自提点列表
* @param $marketingPindanId
* @param int $offset
* @param int $limit
* @return array
*/
public static function getPindanTakePlaceList($marketingPindanId,$offset=0,$limit=20)
{
$where = ['marketing_pindan_id' => $marketingPindanId];
$where['ORDER'] = ['marketing_take_place_id' => 'DESC'];
$where['LIMIT'] = [$offset, $limit];
// $e = MarketingTakePlace::debug();
$relations = MarketingTakePlace::select('*', $where);
$makePlaceIds = array_column($relations,'take_place_id');
$where = ['take_place_id'=>$makePlaceIds,'is_delete'=>TakePlace::STATUS_NORMAL];
$takePlaces = TakePlace::select('*',$where);
return $takePlaces ?: [];
}
}
\ No newline at end of file
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