Commit 41919cd2 authored by luhongguang's avatar luhongguang

update:删除原门店和套餐代码

parent 78388986
<?php
namespace App\Models\goods\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
/**
* Class Setmeal
* 套餐
* @package App\Models\goods\mysql
*/
class Setmeal extends MysqlBase
{
const TABLE_NAME = 'setmeal';
const CONFIG_INDEX = 'goods';
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 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 getAll($goodsSkuId)
{
return self::select('*', ['goods_sku_id' => $goodsSkuId]);
}
}
\ No newline at end of file
<?php
namespace App\Models\goods\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
/**
* Class Stores
* 门店
* @package App\Models\goods\mysql
*/
class Stores extends MysqlBase
{
const TABLE_NAME = 'stores';
const CONFIG_INDEX = 'goods';
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 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 getAll($lifeAccountId)
{
return self::select('*', ['life_account_id' => $lifeAccountId]);
}
}
\ No newline at end of file
......@@ -99,59 +99,6 @@ class GoodsController extends Base
}
/**
* 套餐列表
* todo::可能会去掉
*/
public function setmeal_listAction()
{
(new SetmealListValidate())->validate();
$params = $this->params;
$goodSkuId = $params["goods_sku_id"];
$list = SetmealService::getSetmealList($goodSkuId);
$this->success(["data"=>$list]);
}
/**
* 编辑套餐, 只支持编辑,不支持增加(因为增加时候还没有skuid)
* 这里套餐能一次传多个过来,这里按套餐数组处理
*/
public function edit_setmealAction()
{
(new EditSetmealValidate())->validate();
$params = $this->params;
SetmealService::editSetmeal($params);
$this->success();
}
/**
* 门店列表
* @throws \App\Exception\custom\ParamException
*/
public function stores_listAction()
{
(new StoresListValidate())->validate();
$params = $this->params;
$lifeAccountId = $params["life_account_id"];
$list = StoresService::getStoresList($lifeAccountId);
$this->success(["data"=>$list]);
}
/**
* 编辑门店
*/
public function edit_storesAction()
{
(new EditStoresValidate())->validate();
$params = $this->params;
StoresService::editStores($params);
$this->success();
}
/**
* op后台:商品列表 (spu list)
*/
......
<?php
namespace App\Services\goods;
use App\Exception\custom\GoodsException;
use App\Models\goods\mysql\GoodsSpu;
use App\Models\goods\mysql\Setmeal;
use App\Models\goods\mysql\Stores;
class SetmealService
{
/**
* @param array $params
* 编辑套餐
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws GoodsException
*/
public static function editSetmeal($params = [])
{
$lifeAccountId = $params["life_account_id"];
$goodsSkuId = $params["good_sku_id"];
$setmealData = json_decode($params['setmeal_data'], true);
Setmeal::beginTransaction();
$updateData = $insertData = [];
foreach ($setmealData as $key => $setmeal) {
if (empty($setmeal["name"]) || empty($setmeal["unit"]) || empty($setmeal["unit_number"]) || empty($setmeal["unit_price"])) {
throw new GoodsException(['cus' => 8]);
}
if (!empty($setmeal["setmeal_id"])) {
$updateData[] = [
'setmeal_id' => $setmeal["setmeal_id"],
'life_account_id' => $lifeAccountId,
'goods_sku_id' => $goodsSkuId,
'name' => $setmeal["name"],
'unit' => $setmeal["unit"],
'unit_number' => $setmeal["unit_number"],
'unit_price' => $setmeal["unit_price"] * 100,
];
} else {
$insertData[] = [
'life_account_id' => $lifeAccountId,
'goods_sku_id' => $goodsSkuId,
'name' => $setmeal["name"],
'unit' => $setmeal["unit"],
'unit_number' => $setmeal["unit_number"],
'unit_price' => $setmeal["unit_price"] * 100,
];
}
}
if (!empty($insertData)) {
$ids = GoodsService::getIdgenId(substr($lifeAccountId, -2), "goods", count($insertData));
if (empty($ids)) {
throw new GoodsException(['cus' => 6]);
}
foreach ($insertData as $insertKey => $item) {
//判断重复
$setmeal = Setmeal::getRecordMaster(["goods_sku_id"=>$goodsSkuId, "name"=>$item["name"]]);
if (!empty($setmeal)) {
throw new GoodsException(['cus' => 7]);
}
$item["setmeal_id"] = $ids[$insertKey];
Setmeal::save($item);
}
}
if (!empty($updateData)) {
foreach ($updateData as $item) {
//todo::update去重
$where = [];
$where["setmeal_id"] = $item["setmeal_id"];
unset($item["setmeal_id"]);
Setmeal::save($item, $where);
}
}
if (!Setmeal::commit()) {
Setmeal::rollback();
throw new GoodsException(["cus" => 5]);
}
}
/**
* @param $goodSkuId
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function getSetmealList($goodSkuId)
{
$list = Setmeal::getAll($goodSkuId);
if (!empty($list)) {
foreach ($list as $key => $item) {
$list[$key]["unit_price"] = $item["unit_price"] / 100;
}
}
return $list;
}
}
\ No newline at end of file
<?php
namespace App\Services\goods;
use App\Exception\custom\GoodsException;
use App\Models\goods\mysql\Stores;
class StoresService
{
/**
* @param array $params
* 编辑门店
* @return \Api\PhpUtils\Mysql\MysqlBase
* @throws GoodsException
*/
public static function editStores($params = [])
{
$data = $where = [];
$lifeAccountId = $params["life_account_id"];
$name = $params["name"];
if (!empty($params["stores_id"])) {
$where["stores_id"] = $params["stores_id"];
} else {
$stores = Stores::getRecordMaster(["life_account_id"=>$lifeAccountId, "name"=>$name]);
if (!empty($stores)) {
throw new GoodsException(['cus' => 4]);
}
$res = GoodsService::getIdgenId(substr($lifeAccountId, -2), "goods");
if (empty($res)) {
throw new GoodsException(['cus' => 3]);
}
$data["stores_id"] = $res["0"];
}
$data["name"] = $name;
$data["address_lng"] = $params["address_lng"];
$data["address_lat"] = $params["address_lat"];
$data["address"] = $params["address"];
$data["phone"] = $params["phone"];
$data["life_account_id"] = $params["life_account_id"];
return Stores::save($data, $where);
}
/**
* @param $lifeAccountId
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function getStoresList($lifeAccountId)
{
return Stores::getAll($lifeAccountId);
}
}
\ 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