Commit 55e02dc7 authored by jianghaiming's avatar jianghaiming

update:set

parent 1d47974b
...@@ -17,6 +17,6 @@ class Code ...@@ -17,6 +17,6 @@ class Code
const SHOP = 109000; const SHOP = 109000;
const DISTRIBUTOR = 110000; const DISTRIBUTOR = 110000;
const DISTRIBUTION = 111000; const DISTRIBUTION = 111000;
const MARKETING = 112000;
} }
\ No newline at end of file
...@@ -18,6 +18,18 @@ class DistributorException extends BaseException ...@@ -18,6 +18,18 @@ class DistributorException extends BaseException
protected $cus = [ protected $cus = [
0 => '参数不能为空', 0 => '参数不能为空',
1 => '修改失败', 1 => '修改失败',
2 => '您已经是团长了,不需要重复申请',
3 => '姓名不能为空',
4 => '姓名不合法',
5 => '申请失败',
6 => '手机号不能为空',
7 => '手机号错误',
8 => '已经是二级团长了,不能再申请了',
9 => '分享码不能为空',
10 => '分享码无效',
11 => '短信验证码不能为空',
12 => '类型不能为空',
13 => '姓名不能大于40字符',
14 => '用户id不能能为空',
]; ];
} }
\ No newline at end of file
<?php
namespace App\Exception\custom;
use App\Exception\BaseException;
class MarketingException extends BaseException
{
protected $base_code = Code::MARKETING;
protected $cus = [
0 => '活动名称不能为空',
1 => '活动名称不能大于40',
2 => '活动名称不合法',
3 => '(一级)佣金率不能为空',
4 => '(二级)佣金率不能为空',
5 => '创建失败',
];
}
\ No newline at end of file
<?php <?php
namespace App\Models\distribution\mysql; namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase; use Api\PhpUtils\Mysql\MysqlBase;
class Distributor extends MysqlBase class Distributor extends MysqlBase
{ {
const TABLE_NAME = 'distributor'; const TABLE_NAME = 'distributor';
const CONFIG_INDEX = 'distribution'; const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'id'; const PRIMARY_KEY = 'id';
public static function getRecord($where, $colums = []) public static function getRecord($where, $colums = [])
......
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class DistributorAuditRecord extends MysqlBase
{
const TABLE_NAME = 'distributor_audit_record';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'id';
public static function getRecord($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::get($colums, $where);
}
public static function getRecordMaster($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::selectMaster($colums, $where);
}
public static function insertRecord($colums)
{
return self::insert($colums);
}
public static function updateRecord($colums, $where)
{
return self::update($colums, $where);
}
public static function save($data, $where = [])
{
if (empty($where)) {
return self::insert($data);
}
return self::update($data, $where);
}
public static function deleteRecord($where)
{
return self::delete($where);
}
public static function getRecords($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::select($colums, $where);
}
public static function getCount($where, $columns = "*")
{
if (empty($columns)) {
$columns = '*';
}
return self::count($columns, $where);
}
}
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class Marketing extends MysqlBase
{
const TABLE_NAME = 'marketing';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'marketing_id';
public static function getRecord($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::get($colums, $where);
}
public static function getRecordMaster($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::selectMaster($colums, $where);
}
public static function insertRecord($colums)
{
return self::insert($colums);
}
public static function updateRecord($colums, $where)
{
return self::update($colums, $where);
}
public static function save($data, $where = [])
{
if (empty($where)) {
return self::insert($data);
}
return self::update($data, $where);
}
public static function deleteRecord($where)
{
return self::delete($where);
}
public static function getMarketingList($data, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::select($colums, $data);
}
public static function getRecords($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
if (!empty($where['marketing_name'])) {
$where['marketing_name'] = $where['marketing_name'];
}
if (!empty($where)) {
$data = self::formatWhere($where);
}
if (!empty($where['LIMIT'])) {
$data['LIMIT'] = $where['LIMIT'];
}
if (!empty($where['ORDER'])) {
$data['ORDER'] = $where['ORDER'];
}
return self::select($colums, $data);
}
public static function getCount($where, $columns = "*")
{
if (!empty($where)) {
$where = self::formatWhere($where);
}
if (empty($columns)) {
$columns = '*';
}
return self::count($columns, $where);
}
public static function formatWhere($where)
{
$data = [];
if (!empty($where['marketing_name'])) {
$data['marketing_name[~]'] = $where['marketing_name'];
}
if (!empty($where['marketing_id'])) {
$data['marketing_id'] = $where['marketing_id'];
}
if (!empty($where['online_status'])) {
$data['online_status'] = $where['online_status'];
}
return $data;
}
}
<?php
namespace App\Models\marketing\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class MarketingGoods extends MysqlBase
{
const TABLE_NAME = 'marketing_goods';
const CONFIG_INDEX = 'marketing';
const PRIMARY_KEY = 'id';
public static function marketingGoodsList($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::select($colums, $where);
}
public static function getRecord($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::get($colums, $where);
}
public static function getRecordMaster($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
return self::selectMaster($colums, $where);
}
public static function insertRecord($colums)
{
return self::insert($colums);
}
public static function updateRecord($colums, $where)
{
return self::update($colums, $where);
}
public static function save($data, $where = [])
{
if (empty($where)) {
return self::insert($data);
}
return self::update($data, $where);
}
public static function deleteRecord($where)
{
return self::delete($where);
}
public static function getRecords($where, $colums = [])
{
if (empty($colums)) {
$colums = '*';
}
if (!empty($where['marketing_name'])) {
$where['marketing_name'] = $where['marketing_name'];
}
if (!empty($where)) {
$data = self::formatWhere($where);
}
if (!empty($where['LIMIT'])) {
$data['LIMIT'] = $where['LIMIT'];
}
if (!empty($where['ORDER'])) {
$data['ORDER'] = $where['ORDER'];
}
return self::select($colums, $data);
}
public static function getCount($where, $columns = "*")
{
if (!empty($where)) {
$where = self::formatWhere($where);
}
if (empty($columns)) {
$columns = '*';
}
return self::count($columns, $where);
}
public static function formatWhere($where)
{
$data = [];
if (!empty($where['marketing_name'])) {
$data['marketing_name[~]'] = $where['marketing_name'];
}
if (!empty($where['marketing_id'])) {
$data['marketing_id'] = $where['marketing_id'];
}
if (!empty($where['online_status'])) {
$data['online_status'] = $where['online_status'];
}
return $data;
}
}
<?php
use App\Base\Base;
use App\Services\Marketing\DistributorService;
use App\Exception\custom\DistributorException;
use Api\PhpUtils\Validate\Validate;
class DistributorController extends Base
{
/**
* 二级团长列表
*
*/
public function second_distributor_listAction()
{
$params = $this->params;
$distributionList = DistributorService::secondDistributor($params);
$this->success($distributionList);
}
/**
* 申请团长
*
*/
public function apply_distributorAction()
{
$params = $this->params;
$distributionList = DistributorService::applyDistributor($params);
$this->success();
}
/**
* 申请二级团长
*
*/
public function apply_second_distributorAction()
{
$params = $this->params;
$distributionList = DistributorService::applySecondDistributor($params);
$this->success();
}
/**
* 申请发送短信
*
*/
public function send_sms_codeAction()
{
$params = $this->params;
$mobile = !empty($params['mobile']) ? $params['mobile'] : '';
if (empty($mobile)) {
throw new DistributorException(['cus'=>6]);
}
$is_mobile = (new Validate)->isMobile($mobile);
if (empty($is_mobile)) {
throw new DistributorException(['cus'=>7]);
}
$params = [
'mobile' => !empty($mobile) ? $mobile : '',
];
$send_data = DistributorService::sendSmsCode($params);
if (!empty($send_data) && $send_data['status'] == 'success' && $send_data['code'] == 0 ) {
$res = [
'reason' => 'ok',
];
$this->success($res);
}else{
$this->failed($send_data['code'],$send_data['reason'],'failed');
die();
}
}
/**
* 获取是否是
*
*/
public function distributorAction()
{
$params = $this->params;
$info = DistributorService::distributor($params);
$this->success(['result' => $info]);
}
/**
* 获取团长列表
* 后台管理
*
*/
public function get_distributor_listAction()
{
$params = $this->params;
$distributionList = DistributorService::getDistributorList($params);
$this->success($distributionList);
}
/**
* 获取详情数据
* 后台管理
*
*/
public function distributor_infoAction()
{
$params = $this->params;
$distributorInfo = DistributorService::distributorInfo($params);
$this->success(['result' => $distributorInfo]);
}
/**
* 更新数据
* 后台管理
*
*/
public function update_distributorAction()
{
$params = $this->params;
$where['distributor_id'] = $params['distributor_id'];
if (!empty($params['audit_status'])) {
$param['audit_status'] = $params['audit_status'];
}
if (!empty($params['audit_user_name'])) {
$param['audit_user_name'] = $params['audit_user_name'];
}
$srt = DistributorService::updateDistributor($param,$where);
if (!empty($srt)) {
$this->success();
}else{
throw new DistributorException(['cus'=>1]);
}
}
/**
* 添加团长
* 后台管理
*
*/
public function add_distributorAction()
{
}
}
\ No newline at end of file
<?php <?php
use App\Base\Base; use App\Base\Base;
use App\Services\distribution\DistributorService; use App\Services\Marketing\MarketingService;
use App\Exception\custom\DistributorException; use App\Exception\custom\MarketingException;
class DistributorController extends Base class MarketingController extends Base
{ {
/** /**
* 获取团长列表 * 营销列表
* 后台管理 * 后台管理
* *
*/ */
public function distributor_listAction() public function marketing_listAction()
{ {
$params = $this->params; $params = $this->params;
$distributionList = DistributorService::distributorList($params); $distributionList = MarketingService::marketingList($params);
$this->success($distributionList); $this->success($distributionList);
} }
/** /**
* 获取详情数据 * 添加团长
* 后台管理 * 后台管理
* *
*/ */
public function distributor_infoAction() public function add_marketingAction()
{ {
$params = $this->params; $params = $this->params;
$distributorInfo = DistributorService::distributorInfo($params); $addMarketing = MarketingService::addMarketing($params);
$this->success(['result' => $distributorInfo]); if (!empty($addMarketing)) {
$this->success();
}
} }
/** /**
* 更新数据 * 更新数据
* 后台管理 * 后台管理
* *
*/ */
public function update_distributorAction() public function update_marketingAction()
{ {
$params = $this->params; $params = $this->params;
$where['distributor_id'] = $params['distributor_id']; $where['marketing_id'] = $params['marketing_id'];
if (!empty($params['audit_status'])) { if (!empty($params['audit_status'])) {
$param['audit_status'] = $params['audit_status']; $param['audit_status'] = $params['audit_status'];
...@@ -49,7 +53,7 @@ class DistributorController extends Base ...@@ -49,7 +53,7 @@ class DistributorController extends Base
$param['audit_user_name'] = $params['audit_user_name']; $param['audit_user_name'] = $params['audit_user_name'];
} }
$srt = DistributorService::updateDistributor($param,$where); $srt = MarketingService::updateMarketing($param,$where);
if (!empty($srt)) { if (!empty($srt)) {
$this->success(); $this->success();
...@@ -58,19 +62,18 @@ class DistributorController extends Base ...@@ -58,19 +62,18 @@ class DistributorController extends Base
} }
} }
/** /**
* 添加团长 * 获取详情数据
* 后台管理 * 后台管理
* *
*/ */
public function add_distributorAction() public function marketing_infoAction()
{ {
$params = $this->params;
$marketingInfo = MarketingService::marketingInfo($params);
$this->success(['result' => $marketingInfo]);
} }
} }
\ No newline at end of file
<?php
use App\Base\Base;
use App\Services\Marketing\MarketingGoodsService;
use App\Exception\custom\DistributorException;
class MarketingGoodsController extends Base
{
/**
* 获取全部生效营销活动商品列表
*
*/
public function marketing_goods_listAction()
{
$params = $this->params;
// $marketingList = Marketing::getMarketingList(['online_status' => 1,'start_time' => date("Y-m-d H:i:s"),'end_time' => date("Y-m-d H:i:s")]);
// print_r( $marketingList);
// die();
$distributionList = MarketingGoodsService::marketingGoodsList($params);
print_r($distributionList);
die();
$this->success($distributionList);
}
}
\ No newline at end of file
<?php
namespace App\Services\goods;
use App\Models\goods\mysql\Category;
class CategoryService
{
public static function getCategoryList()
{
//todo::加上redis
$allCaregoryList = Category::getRecordList([], ['category_id', 'parent_category_id', 'name', 'level']);
$data = [];
if (!empty($allCaregoryList)) {
foreach ($allCaregoryList as $caregory) {
if ($caregory["level"] == Category::LEVEL_1) {
$data["level_1"][] = [
"category_id" => $caregory["category_id"],
"name" => $caregory["name"]
];
}
if ($caregory["level"] == Category::LEVEL_2) {
$data["level_2"][$caregory["parent_category_id"]][] = [
"category_id" => $caregory["category_id"],
"name" => $caregory["name"]
];
}
}
}
return $data;
}
}
\ No newline at end of file
<?php
namespace App\Services\distribution;
use App\Models\distribution\mysql\Distributor;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen;
use App\Exception\custom\DistributorException;
class DistributorService
{
/**
* 查询
*
*/
public static function distributorList($params)
{
$params['page'] = !empty($params['page']) ? $params['page'] : 1;
$limit = !empty($params['page_size']) ? $params['page_size'] : 20;
$page = ($params['page'] - 1) * $limit;
if (!empty($params['audit_status'])) {
$where['audit_status'] = $params['audit_status'];
}
if (!empty($params['audit_user_name'])) {
$where['audit_user_name'] = $params['audit_user_name'];
}
$where['ORDER'] = ["create_time" => "DESC"];
$where['LIMIT'] = [$page, $limit];
$list = Distributor::getRecords($where);
unset($where['LIMIT']);
unset($where['ORDER']);
$count = Distributor::getCount($where);
$data = ['result' => $list,'count' => $count];
return $data;
}
public static function distributorInfo($params)
{
$where['distributor_id'] = !empty($params['distributor_id']) ? $params['distributor_id'] : '';
$info = Distributor::getRecord($where);
return $info;
}
/**
* 更新数据
*
*/
public static function updateDistributor($params,$where)
{
$where['distributor_id'] = !empty($where['distributor_id']) ? $where['distributor_id'] : '';
$info = Distributor::updateRecord($params, $where);
return $info;
}
/**
* 通过发号器拿 id (非雪花)
* number,获取店铺shop_id用生活号id后两位,商品相关的这里是shop_id的后两位
* @param $number
* @param $type
* @param int $count
* @return array|mixed
*/
public static function getIdgenId($number, $type, $count = 1)
{
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [[
"type" => $type,
'number' => (int)$number,
"count" => $count]]);
return $res['id_datetime'][$type] ?? [];
}
public static function getSnowIdgenId($type, $count = 1)
{
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [[
"type" => $type,
"count" => $count]], []);
return $res['id_snow'][$type] ?? [];
}
}
\ No newline at end of file
<?php
namespace App\Services\marketing;
use App\Models\marketing\mysql\Distributor;
use App\Models\marketing\mysql\DistributorAuditRecord;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen;
use App\Exception\custom\DistributorException;
use Api\PhpServices\Sensitive\Sensitive;
use Api\PhpServices\JwUser\JwUser;
use Api\PhpUtils\Common\TimeOut;
use App\Exception\custom\CodeSpecialException;
class DistributorService
{
/**
* 查询二级团长
*
*/
public static function secondDistributor($params)
{
$params['page'] = !empty($params['page']) ? $params['page'] : 1;
$limit = !empty($params['page_size']) ? $params['page_size'] : 20;
$page = ($params['page'] - 1) * $limit;
if (!empty($params['user_id'])) {
$where['user_id'] = $params['user_id'];
}
if (!empty($params['higher_user_id'])) {
$where['higher_user_id'] = $params['higher_user_id'];
}
$where['LIMIT'] = [$page, $limit];
$where['ORDER'] = ["create_time" => "DESC"];
$list = Distributor::getRecords($where);
$last = end($list);
$lastId = !empty($last['id']) ? $last['id'] : '';
$data = ['result' => $list,'last_id' => $lastId];
return $data;
}
/**
* 登陆用户申请团长
* 一级团长申请
*
*/
public static function applyDistributor($params)
{
$userId = !empty($params['user_id']) ? $params['user_id'] : '';
$userName = !empty($params['user_name']) ? $params['user_name'] : '';
$type = !empty($params['type']) ? $params['type'] : '';
$info = Distributor::getRecord(['user_id' => $userId,'type' => $type]);
if (!empty($info)) {
throw new DistributorException(['cus'=>2]);
}
if (empty($userName)) {
throw new DistributorException(['cus'=>3]);
}
if (empty($type)) {
throw new DistributorException(['cus'=>12]);
}
$detectParams = [
'businessId' => 1,
'text' => !empty($userName) ? $userName : '',
'scene' => 1,
];
$sensitive = (new Sensitive)->detect($detectParams);
if (!empty($sensitive['data'])) {
throw new DistributorException(['cus'=>40]);
}
if (self::utf8Strlen($userName) > 40) {
throw new DistributorException(['cus'=>13]);
}
Distributor::beginTransaction();
$userCode = $userId . '_' . $type;
$data = [
'user_id' => $userId,
'user_name' => $userName,
'update_time' => date("Y-m-d H:i:s"),
'create_time' => date("Y-m-d H:i:s"),
'code' => $userCode,
'type' => $type
];
$id = Distributor::insertRecord($data);
if (empty($id)) {
Distributor::rollback();
throw new DistributorException(['cus' => 5]);
}
//暂时默认通过,
$auditData = [
'user_id' => $userId,
'user_name' => $userName,
'type' => $type,
'status' => 2,
'update_time' => date("Y-m-d H:i:s"),
'create_time' => date("Y-m-d H:i:s"),
'code' => $userCode,
];
$auditId = DistributorAuditRecord::insertRecord($auditData);
if (!empty($auditId)) {
Distributor::commit();
return $auditId;
}else{
Distributor::rollback();
throw new DistributorException(['cus' => 5]);
}
}
/**
* 申请二级团长
*
*/
public static function applySecondDistributor($params)
{
$userId = !empty($params['user_id']) ? $params['user_id'] : '';
$userName = !empty($params['user_name']) ? $params['user_name'] : '';
$mobile = !empty($params['mobile']) ? $params['mobile'] : '';
$code = !empty($params['code']) ? $params['code'] : '';
$smsCode = !empty($params['sms_code']) ? $params['sms_code'] : '';
if (empty($smsCode)) {
throw new DistributorException(['cus'=>11]);
}
$jwUserId = '';
if (empty($code)) {
throw new DistributorException(['cus'=>9]);
}
$info = Distributor::getRecord(['code' => $code]);
if (empty($info)) {
throw new DistributorException(['cus'=>10]);
}
$higherUserId = !empty($info['user_id']) ? $info['user_id'] : '';
$type = !empty($info['type']) ? $info['type'] : '';
if (empty($mobile)) {
throw new DistributorException(['cus'=>6]);
}
$param = [
'mobile' => $mobile,
];
$jwUser = new JwUser();
$userInfo = $jwUser->getUserInfo($params);
if (!empty($userInfo) && $userInfo['result'] == 0) {
if (!empty($userInfo['data'])) {
$jwUserId = !empty($userInfo['data']['userId']) ? $userInfo['data']['userId'] : '';
}
}else{
throw new DistributorException(['cus'=>7]);
}
$info = Distributor::getRecord(['user_id' => $jwUserId]);
if (!empty($info) && $info['higher_user_id'] > 0) {
throw new DistributorException(['cus'=>8]);
}
if (empty($userName)) {
throw new DistributorException(['cus'=>3]);
}
$detectParams = [
'businessId' => 1,
'text' => !empty($userName) ? $userName : '',
'scene' => 1,
];
$sensitive = (new Sensitive)->detect($detectParams);
if (!empty($sensitive['data'])) {
throw new DistributorException(['cus'=>4]);
}
if (self::utf8Strlen($userName) > 40) {
throw new DistributorException(['cus'=>13]);
}
Distributor::beginTransaction();
$userCode = $jwUserId . '_' . $type;
if (empty($info)) {
// $res = self::getIdgenId(1, 'goods', $count = 1);
// $userCode = !empty($res[0]) ? $res[0] : '';
//新增
$data = [
'higher_user_id' => $higherUserId,
'user_id' => $jwUserId,
'user_name' => $userName,
'update_time' => date("Y-m-d H:i:s"),
'create_time' => date("Y-m-d H:i:s"),
'code' => $userCode,
'type' => $type
];
$id = Distributor::insertRecord($data);
if (empty($id)) {
Distributor::rollback();
throw new DistributorException(['cus' => 5]);
}
}else{
//编辑二级团长
$data = [
'higher_user_id' => $higherUserId,
'user_name' => $userName,
'update_time' => date("Y-m-d H:i:s"),
'create_time' => date("Y-m-d H:i:s"),
];
$id = Distributor::updateRecord($data, ['user_id' => $jwUserId,'type' => $type]);
if (empty($id)) {
Distributor::rollback();
throw new DistributorException(['cus' => 5]);
}
}
//暂时默认通过,
$auditData = [
'higher_user_id' => $higherUserId,
'user_id' => $jwUserId,
'user_name' => $userName,
'type' => $type,
'status' => 2,
'update_time' => date("Y-m-d H:i:s"),
'create_time' => date("Y-m-d H:i:s"),
'code' => $userCode,
];
$auditId = DistributorAuditRecord::insertRecord($auditData);
if (!empty($auditId)) {
Distributor::commit();
return $auditId;
}else{
Distributor::rollback();
throw new DistributorException(['cus' => 5]);
}
}
/**
* 发送短信验证码
*
*/
public static function sendSmsCode($params)
{
$url = config('interface','service.user.send_sms_code');
if(!$url){
throw new CodeSpecialException("failed");
}
if (empty($params)) {
throw new CodeSpecialException("failed");
}
$params = [
'mobile' => !empty($params['mobile']) ? $params['mobile'] : '',
'appid' => 'hubble',
'code' => '123456',
'key' => 'f16bdd46292480b4b82c841d90a6ba02',
'partner' => 'merchant-b',
'template' =>7,
'code_lenght' => 6,
'ticket_expire' => 86400,
'resend_times' => 5,
'retry_times' => 100
];
$sms = (new TimeOut())->runGet($url, $params);
if(!$sms){
throw new CodeSpecialException("timeout");
}
if (!empty($sms) && $sms['code'] == 0) {
return $sms;
}else{
return $sms;
}
}
public static function distributor($params)
{
if (empty($params['user_id'])) {
throw new DistributorException(['cus' => 14]);
}
$where['user_id'] = $params['user_id'];
$data = [];
$info = Distributor::getRecord($where);
if (!empty($info)) {
$data['code'] = $info['code'];
$data['is_distributor'] = 1;
}else{
$data['code'] = $info['code'];
$data['is_distributor'] = 0;
}
return $data ;
}
/**
* 查询
* 后台管理
*/
public static function distributorList($params)
{
$params['page'] = !empty($params['page']) ? $params['page'] : 1;
$limit = !empty($params['page_size']) ? $params['page_size'] : 20;
$page = ($params['page'] - 1) * $limit;
if (!empty($params['audit_status'])) {
$where['audit_status'] = $params['audit_status'];
}
if (!empty($params['audit_user_name'])) {
$where['audit_user_name'] = $params['audit_user_name'];
}
$where['ORDER'] = ["create_time" => "DESC"];
$where['LIMIT'] = [$page, $limit];
$list = Distributor::getRecords($where);
unset($where['LIMIT']);
unset($where['ORDER']);
$count = Distributor::getCount($where);
$data = ['result' => $list,'count' => $count];
return $data;
}
public static function distributorInfo($params)
{
$where['distributor_id'] = !empty($params['distributor_id']) ? $params['distributor_id'] : '';
$info = Distributor::getRecord($where);
return $info;
}
/**
* 更新数据
*
*/
public static function updateDistributor($params,$where)
{
$where['distributor_id'] = !empty($where['distributor_id']) ? $where['distributor_id'] : '';
$info = Distributor::updateRecord($params, $where);
return $info;
}
/**
*判断长度
*
*/
public static function utf8Strlen($string = null) {
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// // 返回单元个数
return count($match[0]);
}
/**
* 通过发号器拿 id (非雪花)
* number,获取店铺shop_id用生活号id后两位,商品相关的这里是shop_id的后两位
* @param $number
* @param $type
* @param int $count
* @return array|mixed
*/
public static function getIdgenId($number, $type, $count = 1)
{
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [[
"type" => $type,
'number' => (int)$number,
"count" => $count]]);
return $res['id_datetime'][$type] ?? [];
}
public static function getSnowIdgenId($type, $count = 1)
{
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [[
"type" => $type,
"count" => $count]], []);
return $res['id_snow'][$type] ?? [];
}
}
\ No newline at end of file
<?php
namespace App\Services\marketing;
use App\Models\marketing\mysql\Marketing;
use App\Models\marketing\mysql\MarketingGoods;
use App\Models\goods\mysql\GoodsSku;
use App\Models\goods\mysql\GoodsSpu;
use App\Models\shop\mysql\SubShop;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen;
use App\Exception\custom\MarketingException;
use Api\PhpServices\Sensitive\Sensitive;
class MarketingGoodsService
{
public static function marketingGoodsList($params)
{
$where = [];
$marketingWhere = [
"end_time[>]" => date("Y-m-d"),
"online_status" => 1,
];
$marketingList = Marketing::getMarketingList($marketingWhere);
$marketingId = array_column($marketingList, 'marketing_id');
$where['marketing_id'] = !empty($marketingId) ? $marketingId : [];
$data = MarketingGoods::marketingGoodsList($where);
$goodsSkuId = array_column($data, 'goods_sku_id');
$goodsSkuList = GoodsSku::getRecordMaster(['goods_sku_id' => $goodsSkuId]);
$goodsSkuList = array_column($goodsSkuList,null,'goods_sku_id');
$shopId = [];
foreach ($data as $key => $value) {
$shopId[$key] = !empty($goodsSkuList[$value['goods_sku_id']]['shop_id']) ? $goodsSkuList[$value['goods_sku_id']]['shop_id'] : '';
}
$subShopList = SubShop::getRecords(['shop_id' => $shopId]);
print_r($subShopList);
die();
$list = [];
foreach ($data as $key => $value) {
$list[$key] = $value;
$list[$key]['life_account_id'] = !empty($goodsSkuList[$value['goods_sku_id']]['life_account_id']) ? $goodsSkuList[$value['goods_sku_id']]['life_account_id'] : '';
$list[$key]['shop_id'] = !empty($goodsSkuList[$value['goods_sku_id']]['shop_id']) ? $goodsSkuList[$value['goods_sku_id']]['shop_id'] : '';
$list[$key]['goods_name'] = !empty($goodsSkuList[$value['goods_sku_id']]['name']) ? $goodsSkuList[$value['goods_sku_id']]['name'] : '';
$list[$key]['goods_desc'] = !empty($goodsSkuList[$value['goods_sku_id']]['desc']) ? $goodsSkuList[$value['goods_sku_id']]['desc'] : '';
$list[$key]['goods_spu_id'] = !empty($goodsSkuList[$value['goods_sku_id']]['goods_spu_id']) ? $goodsSkuList[$value['goods_sku_id']]['goods_spu_id'] : '';
$list[$key]['original_price'] = !empty($goodsSkuList[$value['goods_sku_id']]['original_price']) ? $goodsSkuList[$value['goods_sku_id']]['original_price'] : '';
$list[$key]['price'] = !empty($goodsSkuList[$value['goods_sku_id']]['price']) ? $goodsSkuList[$value['goods_sku_id']]['price'] : '';
$list[$key]['total_amount_order'] = !empty($goodsSkuList[$value['goods_sku_id']]['total_amount_order']) ? $goodsSkuList[$value['goods_sku_id']]['total_amount_order'] : '';
$list[$key]['url'] = !empty($goodsSkuList[$value['goods_sku_id']]['url']) ? $goodsSkuList[$value['goods_sku_id']]['url'] : '';
$shopId = !empty($list[$key]['shop_id']) ? $list[$key]['shop_id'] : '';
}
return $list;
}
}
<?php
namespace App\Services\marketing;
use App\Models\marketing\mysql\Marketing;
use App\Models\marketing\mysql\MarketingGoods;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen;
use App\Exception\custom\MarketingException;
use Api\PhpServices\Sensitive\Sensitive;
class MarketingService
{
/**
* 查询
*
*/
public static function marketingList($params)
{
$params['page'] = !empty($params['page']) ? $params['page'] : 1;
$limit = !empty($params['page_size']) ? $params['page_size'] : 20;
$page = ($params['page'] - 1) * $limit;
if (!empty($params['marketing_name'])) {
$where['marketing_name'] = $params['marketing_name'];
}
if (!empty($params['marketing_id'])) {
$where['marketing_id'] = $params['marketing_id'];
}
if (!empty($params['online_status'])) {
$where['online_status'] = $params['online_status'];
}
$where['ORDER'] = ["create_time" => "DESC"];
$where['LIMIT'] = [$page, $limit];
$list = Marketing::getRecords($where);
unset($where['LIMIT']);
unset($where['ORDER']);
$count = Marketing::getCount($where);
$data = ['result' => $list,'count' => $count];
return $data;
}
public static function addMarketing($params){
$marketingName = !empty($params['marketing_name']) ? $params['marketing_name'] : '';
$firstCommissionRate = !empty($params['first_commission_rate']) ? $params['first_commission_rate'] : '';
$secondCommissionRate = !empty($params['second_commission_rate']) ? $params['second_commission_rate'] : '';
$createUserEmail = !empty($params['op_cur_user']) ? $params['op_cur_user'] : '';
$startTime = !empty($params['start_time']) ? $params['start_time'] : '';
$endTime = !empty($params['end_time']) ? $params['end_time'] : '';
$type = !empty($params['type']) ? $params['type'] : 1;
$goodsSkuId = !empty($params['goods_sku_id']) ? explode(",", $params['goods_sku_id']) : [];
if (empty($marketingName)) {
throw new MarketingException(['cus'=>0]);
}
// if (empty($firstCommissionRate)) {
// throw new MarketingException(['cus'=>3]);
// }
// if (empty($secondCommissionRate)) {
// throw new MarketingException(['cus'=>4]);
// }
if (self::utf8Strlen($marketingName) > 40) {
throw new MarketingException(['cus'=>1]);
}
$detectParams = [
'businessId' => 1,
'text' => !empty($marketingName) ? $marketingName : '',
'scene' => 1,
];
$sensitive = (new Sensitive)->detect($detectParams);
if (!empty($sensitive['data'])) {
throw new MarketingException(['cus'=>2]);
}
// //判断重复
// if (!self::isName($name)) {
// throw new ShopException(['cus'=>6]);
// }
//$res = self::getIdgenId(1, 'goods', $count = 1);
//$stores_id = !empty($res[0]) ? $res[0] : '';
Marketing::beginTransaction();
$colums = [
//'marketing_id' => $marketing_id,
'marketing_name' => $marketingName,
'first_commission_rate' => $firstCommissionRate,
'second_commission_rate' => $secondCommissionRate,
'create_user_email' => $createUserEmail,
'good_count' => 0,
'start_time' => $startTime,
'end_time' => $endTime,
'online_status' => 1,
'type' => $type,
'update_user_email' => $createUserEmail,
'update_time' => date("Y-m-d H:i:s"),
'create_time' => date("Y-m-d H:i:s"),
];
$marketingId = Marketing::insertRecord($colums);
if (empty($marketingId)) {
Marketing::rollback();
throw new MarketingException(['cus' => 5]);
}
$colums = [];
$goodCount = !empty($goodsSkuId) ? count($goodsSkuId) : 0;
foreach ($goodsSkuId as $key => $value) {
$colums[$key]['marketing_id'] = $marketingId;
$colums[$key]['goods_spu_id'] = $value;
$colums[$key]['goods_sku_id'] = '';
$colums[$key]['update_time'] = date("Y-m-d H:i:s");
$colums[$key]['create_time'] = date("Y-m-d H:i:s");
}
$info = MarketingGoods::insertRecord($colums);
if (empty($info)) {
Marketing::rollback();
throw new MarketingException(['cus' => 5]);
}
$srt = Marketing::updateRecord(['good_count' => $goodCount], ['marketing_id' => $marketingId]);
if (!empty($srt)) {
Marketing::commit();
return $srt;
}else{
Marketing::rollback();
throw new MarketingException(['cus' => 5]);
}
}
/**
* 更新数据
*
*/
public static function updateMarketing($params,$where)
{
$where['marketing_id'] = !empty($where['marketing_id']) ? $where['marketing_id'] : '';
$info = Marketing::updateRecord($params, $where);
return $info;
}
public static function marketingInfo($params)
{
$where['marketing_id'] = !empty($params['marketing_id']) ? $params['marketing_id'] : '';
$info = Marketing::getRecord($where);
return $info;
}
/**
*判断长度
*
*/
public static function utf8Strlen($string = null) {
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// // 返回单元个数
return count($match[0]);
}
/**
* 通过发号器拿 id (非雪花)
* number,获取店铺shop_id用生活号id后两位,商品相关的这里是shop_id的后两位
* @param $number
* @param $type
* @param int $count
* @return array|mixed
*/
public static function getIdgenId($number, $type, $count = 1)
{
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [[
"type" => $type,
'number' => (int)$number,
"count" => $count]]);
return $res['id_datetime'][$type] ?? [];
}
public static function getSnowIdgenId($type, $count = 1)
{
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [[
"type" => $type,
"count" => $count]], []);
return $res['id_snow'][$type] ?? [];
}
}
\ No newline at end of file
...@@ -3,7 +3,7 @@ application.directory = APP_PATH ...@@ -3,7 +3,7 @@ application.directory = APP_PATH
application.bootstrap = APP_PATH "/Bootstrap.php" application.bootstrap = APP_PATH "/Bootstrap.php"
application.library = APP_PATH"/library" application.library = APP_PATH"/library"
application.library.namespace = "" application.library.namespace = ""
application.modules="Index,Test,Goods,Shop,Distribution" application.modules="Index,Test,Goods,Shop,Marketing"
appid = "goods" appid = "goods"
;AES密钥 ;AES密钥
......
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