Commit f73c5222 authored by jianghaiming's avatar jianghaiming

update:set

parent fc318f70
......@@ -14,4 +14,5 @@ class Code
const PARAM = 101000;
const SIGN = 102000;
const GOODS = 108000;
const SHOP = 109000;
}
\ No newline at end of file
<?php
namespace App\Exception\custom;
use App\Exception\BaseException;
class ShopException extends BaseException
{
protected $base_code = Code::SHOP;
protected $cus = [
0 => '生活号不能为空',
1 => '手机号不能为空',
2 => '手机号格式不正确',
3 => '门店名称不能为空',
4 => '标题不合法,涉及敏感词',
5 => '门店创建失败',
6 => '门店名称已存在',
7 => '手机号已存在',
8 => '门店名称不能大于20个字',
];
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ if (!function_exists('config')) {
*/
function config($file, $param = ''){
if (empty($file) || !file_exists(ROOT_PATH."/yaconf/".$file.".ini")){
return "";
//return "";
}
$env = Application::app()->environ() ?? "dev";
......
<?php
namespace App\Models\distribution\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class Distribution extends MysqlBase
{
const TABLE_NAME = 'distribution';
const CONFIG_INDEX = 'distribution';
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)
{
return self::count($where);
}
}
<?php
namespace App\Models\shop\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class SubShop extends MysqlBase
{
const TABLE_NAME = 'sub_shop';
const CONFIG_INDEX = 'goods';
const PRIMARY_KEY = 'stores_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)
{
$options['rowCount'] = true;
return self::insert($colums,$options);
}
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)
{
return self::count($where);
}
}
<?php
namespace App\Models\shop\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class Distributor extends MysqlBase
{
const TABLE_NAME = 'shop';
const CONFIG_INDEX = 'goods';
const PRIMARY_KEY = 'shop_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)
{
return self::count($where);
}
}
......@@ -18,7 +18,7 @@ class SubShop extends MysqlBase
if (empty($colums)) {
$colums = '*';
}
self::get($colums, $where);
return self::get($colums, $where);
}
public static function getRecordMaster($where, $colums = [])
{
......@@ -30,7 +30,8 @@ class SubShop extends MysqlBase
public static function insertRecord($colums)
{
return self::insert($colums);
$options['rowCount'] = true;
return self::insert($colums,$options);
}
public static function updateRecord($colums, $where)
......
<?php
use App\Base\Base;
use App\Services\distribution\DistributionService;
use App\Exception\custom\ShopException;
class DistributionController extends Base
{
public function get_distribution_listAction()
{
$params = $this->getRequest()->getRequest();
print_r( $params);
die();
$srt = DistributionService::addDistribution($params);
print_r($srt);
}
}
\ No newline at end of file
<?php
use App\Base\Base;
use App\Models\shop\mysql\Shop;
use App\Models\shop\mysql\SubShop;
// use Validate\ShopValidate;
// use App\Exception\custom\ShopException;
use App\Services\shop\ShopService;
use App\Exception\custom\ShopException;
class ShopController extends Base
{
public function get_shop_listAction()
/**
* 创建店铺
*
*/
public function add_shopAction()
{
//$params = $this->getRequest()->getRequest();
$where['life_account_id'] = 0;
$subShop = SubShop::getRecord($where);
print_r($subShop);
$params = $this->getRequest()->getRequest();
$shop = ShopService::addShop($params);
if (!empty($shop)) {
$this->success();
}else{
throw new ShopException(['cus'=>5]);
}
}
/**
* 门店列表
*
*/
public function get_shop_listAction()
{
$params = $this->getRequest()->getRequest();
$subShopList = ShopService::getShopList($params);
$this->success(['result' => $subShopList]);
}
}
}
\ 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\shop\mysql\Distribution;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen;
class DistributionService
{
public static function addDistribution($params)
{
$params = [
];
Distribution::insertRecord($params);
}
public static function getDistributionList($params)
{
}
/**
* 通过发号器拿 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\shop;
use App\Models\shop\mysql\Shop;
use App\Models\shop\mysql\SubShop;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen;
// use Validate\ShopValidate;
use App\Exception\custom\ShopException;
use Api\PhpServices\Sensitive\Sensitive;
class DistributorService
{
public static function addShop($params)
{
$life_account_id = !empty($params['life_account_id']) ? $params['life_account_id'] : '';
$phone = !empty($params['phone']) ? $params['phone'] : '';
$shop_id = !empty($params['shop_id']) ? $params['shop_id'] : '';
$name = !empty($params['name']) ? $params['name'] : '';
$address_lng = !empty($params['address_lng']) ? $params['address_lng'] : '';
$address_lat = !empty($params['address_lat']) ? $params['address_lat'] : '';
$address = !empty($params['address']) ? $params['address'] : '';
if (empty($life_account_id)) {
throw new ShopException(['cus'=>0]);
}
if (empty($phone)) {
throw new ShopException(['cus'=>1]);
}
// $is_mobile = ( new Validate)->isMobile($phone);
// if (empty($is_mobile)) {
// throw new ShopException(['cus'=>2]);
// }
if (empty($name)) {
throw new ShopException(['cus'=>3]);
}
if (self::utf8Strlen($name) > 20) {
throw new ShopException(['cus'=>8]);
}
$detectParams = [
'businessId' => 1,
'text' => !empty($name) ? $name : '',
'scene' => 1,
];
$sensitive = (new Sensitive)->detect($detectParams);
if (!empty($sensitive['data'])) {
throw new ShopException(['cus'=>4]);
}
//判断店铺重复
if (!self::isName($name)) {
throw new ShopException(['cus'=>6]);
}
//判断手机号重复
if (!self::isPhone($phone)) {
throw new ShopException(['cus'=>7]);
}
$res = self::getIdgenId(1, 'goods', $count = 1);
$stores_id = !empty($res[0]) ? $res[0] : '';
$colums = [
'stores_id' => $stores_id,
'life_account_id' => $life_account_id,
'shop_id' => $shop_id,
'name' => $name,
'address_lng' => $address_lng,
'address_lat' => $address_lat,
'address' => $address,
'phone' => $phone,
'create_time' => date("Y-m-d H:i:s"),
];
$subShop = SubShop::insertRecord($colums);
return $subShop;
}
public static function getShopList($params)
{
$life_account_id = !empty($params['life_account_id']) ? $params['life_account_id'] : '';
$phone = !empty($params['phone']) ? $params['phone'] : '';
$shop_id = !empty($params['shop_id']) ? $params['shop_id'] : '';
$name = !empty($params['name']) ? $params['name'] : '';
$address_lng = !empty($params['address_lng']) ? $params['address_lng'] : '';
$address_lat = !empty($params['address_lat']) ? $params['address_lat'] : '';
$address = !empty($params['address']) ? $params['address'] : '';
$where['life_account_id'] = $life_account_id;
$where['ORDER'] = ["create_time" => "DESC"];
$subShopList = SubShop::getRecords($where);
return $subShopList;
}
/**
* 门店名称是否重复
*
*/
public static function isName($name='')
{
if (empty($name)) {
return false;
}
$colums = [
'name' => $name
];
$subShop = SubShop::getRecord($colums);
if (!empty($subShop)) {
return false;
}
return true;
}
/**
* 门店手机号是否重复
*
*/
public static function isPhone($phone='')
{
if (empty($phone)) {
return false;
}
$colums = [
'phone' => $phone
];
$subShop = SubShop::getRecord($colums);
if (!empty($subShop)) {
return false;
}
return true;
}
/**
*判断长度
*
*/
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\shop;
use App\Models\shop\mysql\Shop;
use App\Models\shop\mysql\SubShop;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen;
// use Validate\ShopValidate;
use App\Exception\custom\ShopException;
use Api\PhpServices\Sensitive\Sensitive;
class ShopService
{
public static function addShop($params)
{
$life_account_id = !empty($params['life_account_id']) ? $params['life_account_id'] : '';
$phone = !empty($params['phone']) ? $params['phone'] : '';
$shop_id = !empty($params['shop_id']) ? $params['shop_id'] : '';
$name = !empty($params['name']) ? $params['name'] : '';
$address_lng = !empty($params['address_lng']) ? $params['address_lng'] : '';
$address_lat = !empty($params['address_lat']) ? $params['address_lat'] : '';
$address = !empty($params['address']) ? $params['address'] : '';
if (empty($life_account_id)) {
throw new ShopException(['cus'=>0]);
}
if (empty($phone)) {
throw new ShopException(['cus'=>1]);
}
// $is_mobile = ( new Validate)->isMobile($phone);
// if (empty($is_mobile)) {
// throw new ShopException(['cus'=>2]);
// }
if (empty($name)) {
throw new ShopException(['cus'=>3]);
}
if (self::utf8Strlen($name) > 20) {
throw new ShopException(['cus'=>8]);
}
$detectParams = [
'businessId' => 1,
'text' => !empty($name) ? $name : '',
'scene' => 1,
];
$sensitive = (new Sensitive)->detect($detectParams);
if (!empty($sensitive['data'])) {
throw new ShopException(['cus'=>4]);
}
//判断店铺重复
if (!self::isName($name)) {
throw new ShopException(['cus'=>6]);
}
//判断手机号重复
if (!self::isPhone($phone)) {
throw new ShopException(['cus'=>7]);
}
$res = self::getIdgenId(1, 'goods', $count = 1);
$stores_id = !empty($res[0]) ? $res[0] : '';
$colums = [
'stores_id' => $stores_id,
'life_account_id' => $life_account_id,
'shop_id' => $shop_id,
'name' => $name,
'address_lng' => $address_lng,
'address_lat' => $address_lat,
'address' => $address,
'phone' => $phone,
'create_time' => date("Y-m-d H:i:s"),
];
$subShop = SubShop::insertRecord($colums);
return $subShop;
}
public static function getShopList($params)
{
$life_account_id = !empty($params['life_account_id']) ? $params['life_account_id'] : '';
$phone = !empty($params['phone']) ? $params['phone'] : '';
$shop_id = !empty($params['shop_id']) ? $params['shop_id'] : '';
$name = !empty($params['name']) ? $params['name'] : '';
$address_lng = !empty($params['address_lng']) ? $params['address_lng'] : '';
$address_lat = !empty($params['address_lat']) ? $params['address_lat'] : '';
$address = !empty($params['address']) ? $params['address'] : '';
$where['life_account_id'] = $life_account_id;
$where['ORDER'] = ["create_time" => "DESC"];
$subShopList = SubShop::getRecords($where);
return $subShopList;
}
/**
* 门店名称是否重复
*
*/
public static function isName($name='')
{
if (empty($name)) {
return false;
}
$colums = [
'name' => $name
];
$subShop = SubShop::getRecord($colums);
if (!empty($subShop)) {
return false;
}
return true;
}
/**
* 门店手机号是否重复
*
*/
public static function isPhone($phone='')
{
if (empty($phone)) {
return false;
}
$colums = [
'phone' => $phone
];
$subShop = SubShop::getRecord($colums);
if (!empty($subShop)) {
return false;
}
return true;
}
/**
*判断长度
*
*/
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\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
......@@ -3,7 +3,7 @@ application.directory = APP_PATH
application.bootstrap = APP_PATH "/Bootstrap.php"
application.library = APP_PATH"/library"
application.library.namespace = ""
application.modules="Index,Test,Goods,Shop"
application.modules="Index,Test,Goods,Shop,Distribution"
appid = "goods"
;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