This commit is contained in:
尖叫 2024-02-02 10:31:17 +08:00
parent faa2bb5777
commit eedf770a8d
3 changed files with 68 additions and 66 deletions

View File

@ -61,8 +61,8 @@ class Goods extends \yii\db\ActiveRecord
[['attr_groups', 'plugin_sign'], 'trim'],
[['cx_mch_id', 'goods_hub_id', 'status', 'use_attr', 'goods_stock', 'virtual_sales', 'confine_count', 'freight_id', 'sort', 'created_at', 'updated_at', 'deleted_at', 'is_delete', 'payment_people', 'payment_num', 'payment_order', 'sales', 'viewed_count'], 'integer'],
[['goods_hub_id', 'attr_groups'], 'required'],
[['price', 'payment_amount'], 'number'],
[['attr_groups'], 'string'],
[['payment_amount'], 'number'],
[['attr_groups', 'price'], 'string'],
[['plugin_sign'], 'string', 'max' => 255],
];
}
@ -100,13 +100,14 @@ class Goods extends \yii\db\ActiveRecord
}
public function beforeSave($insert) {
if(parent::beforeSave($insert)){
if($this->isNewRecord){
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->isNewRecord) {
$this->created_at = time();
}
$this->updated_at = time();
if($this->is_delete == 1)
if ($this->is_delete == 1)
$this->deleted_at = time();
return true;
} else {
@ -132,14 +133,14 @@ class Goods extends \yii\db\ActiveRecord
}
//浏览事件
public static function handleViewEvent($goods_id, $cx_mch_id=0)
public static function handleViewEvent($goods_id, $cx_mch_id = 0)
{
$goods = Goods::findOne(['id' => $goods_id, 'is_delete' => 0, 'cx_mch_id' => $cx_mch_id]);
if($goods == null){
if ($goods == null) {
return Model::asReturnError('商品不存在');
}
$goods->viewed_count += 1;
if(!$goods->save()){
if (!$goods->save()) {
return (new Model())->getModelError($goods);
}
return Model::asReturnSuccess();
@ -155,15 +156,15 @@ class Goods extends \yii\db\ActiveRecord
public static function handleStock($goods_id, $goods_attr_id, $num, $type = 1, $cx_mch_id = 0)
{
$goods = Goods::findOne(['id' => $goods_id, 'is_delete' => 0, 'cx_mch_id' => $cx_mch_id]);
if($goods == null){
if ($goods == null) {
return Model::asReturnError('商品不存在');
}
$goods_attr = GoodsAttr::findOne(['goods_id' => $goods_id, 'id' => $goods_attr_id, 'is_delete' => 0, 'cx_mch_id' => $cx_mch_id]);
if($goods_attr == null){
if ($goods_attr == null) {
return Model::asReturnError('商品规格不存在');
}
$goods_attr->stock += $type == 1 ? $num : $num * -1;
if(!$goods_attr->save()){
if (!$goods_attr->save()) {
return (new Model())->getModelError($goods_attr);
}
$goods_stock = GoodsAttr::find()
@ -174,7 +175,7 @@ class Goods extends \yii\db\ActiveRecord
])
->sum('stock');
$goods->goods_stock = $goods_stock;
if(!$goods->save()){
if (!$goods->save()) {
return (new Model())->getModelError($goods);
}
return Model::asReturnSuccess();
@ -185,7 +186,7 @@ class Goods extends \yii\db\ActiveRecord
public static function handleOrderPayAfter($order_id, $cx_mch_id = 0)
{
$order = Order::findOne(['id' => $order_id, 'is_delete' => 0, 'is_pay' => 1, 'cancel_status' => 0, 'cx_mch_id' => $cx_mch_id]);
if($order == null){
if ($order == null) {
return Model::asReturnError('订单不存在');
}
//订单详情
@ -201,9 +202,9 @@ class Goods extends \yii\db\ActiveRecord
$payment_people = 1;
$payment_order = 1;
$details = [];
foreach($order_details as $order_detail){
foreach ($order_details as $order_detail) {
$goods_id = $order_detail['goods_id'];
if(!isset($details[$goods_id])){
if (!isset($details[$goods_id])) {
$details[$goods_id] = [
'goods_id' => $goods_id,
'payment_num' => $order_detail['num'],
@ -216,16 +217,16 @@ class Goods extends \yii\db\ActiveRecord
$details[$goods_id]['payment_amount'] += $order_detail['total_price'];
}
}
foreach ($details as $detail){
foreach ($details as $detail) {
$goods = Goods::findOne(['id' => $detail['goods_id'], 'is_delete' => 0, 'cx_mch_id' => $cx_mch_id]);
if($goods == null)
if ($goods == null)
continue;
$goods->payment_amount += $detail['payment_amount'];
$goods->payment_num += $detail['payment_num'];
$goods->sales += $detail['sales'];
$goods->payment_order += $payment_order;
$goods->payment_people += $payment_people;
if(!$goods->save()){
if (!$goods->save()) {
return (new Model())->getModelError($goods);
}
}
@ -235,8 +236,8 @@ class Goods extends \yii\db\ActiveRecord
//处理订单退款后
public static function handleOrderRefundAfter($order_id, $cx_mch_id = 0)
{
$order = Order::findOne(['id' => $order_id, 'is_delete' => 0, 'is_pay' => 1, 'cancel_status' => [0,1], 'cx_mch_id' => $cx_mch_id]);
if($order == null){
$order = Order::findOne(['id' => $order_id, 'is_delete' => 0, 'is_pay' => 1, 'cancel_status' => [0, 1], 'cx_mch_id' => $cx_mch_id]);
if ($order == null) {
return Model::asReturnError('订单不存在');
}
//订单详情
@ -252,9 +253,9 @@ class Goods extends \yii\db\ActiveRecord
$payment_people = 1;
$payment_order = 1;
$details = [];
foreach($order_details as $order_detail){
foreach ($order_details as $order_detail) {
$goods_id = $order_detail['goods_id'];
if(!isset($details[$goods_id])){
if (!isset($details[$goods_id])) {
$details[$goods_id] = [
'goods_id' => $goods_id,
'payment_num' => 0,
@ -267,16 +268,16 @@ class Goods extends \yii\db\ActiveRecord
$details[$goods_id]['payment_amount'] += $order_detail['total_price'];
}
}
foreach ($details as $detail){
foreach ($details as $detail) {
$goods = Goods::findOne(['id' => $detail['goods_id'], 'is_delete' => 0, 'cx_mch_id' => $cx_mch_id]);
if($goods == null)
if ($goods == null)
continue;
$goods->payment_amount -= $detail['payment_amount'];
$goods->payment_num -= $detail['payment_num'];
$goods->sales -= $detail['sales'];
$goods->payment_order -= $payment_order;
$goods->payment_people -= $payment_people;
if(!$goods->save()){
if (!$goods->save()) {
return (new Model())->getModelError($goods);
}
}
@ -287,13 +288,13 @@ class Goods extends \yii\db\ActiveRecord
//获取商品规格信息
public static function getGoodsAttrInfoListBySignId($sign_id, $attr_groups)
{
if(empty($attr_groups))
if (empty($attr_groups))
return [];
$attr_info_list = [];
$sign_ids = explode(':', $sign_id);
foreach ($sign_ids as $attr_id){
foreach ($sign_ids as $attr_id) {
$attr_info = self::getGoodsAttrInfoByAttrId($attr_id, $attr_groups);
if(!empty($attr_info)){
if (!empty($attr_info)) {
$attr_info_list[] = $attr_info;
}
}
@ -303,9 +304,9 @@ class Goods extends \yii\db\ActiveRecord
public static function getGoodsAttrInfoByAttrId($attr_id, $attr_groups)
{
$attr_info = [];
foreach ($attr_groups as $i => $attr_group){
foreach ($attr_group['attr_list'] as $j => $attr ){
if($attr['attr_id'] == $attr_id){
foreach ($attr_groups as $i => $attr_group) {
foreach ($attr_group['attr_list'] as $j => $attr) {
if ($attr['attr_id'] == $attr_id) {
$attr_info['attr_group_id'] = $attr_group['attr_group_id'];
$attr_info['attr_group_name'] = $attr_group['attr_group_name'];
$attr_info['attr_id'] = $attr['attr_id'];
@ -320,7 +321,7 @@ class Goods extends \yii\db\ActiveRecord
public static function getGoodsAttrInfoToString($sign_id, $attr_groups, $delimiter, $default = "默认")
{
$attr_info_list = self::getGoodsAttrInfoListBySignId($sign_id, $attr_groups);
if(empty($attr_info_list))
if (empty($attr_info_list))
return $default;
return implode($delimiter, array_column($attr_info_list, 'attr_name'));
}

View File

@ -72,16 +72,16 @@ class CommonGoodsEditForm extends Model
{
return [
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'unit', 'plugin_sign', 'goods_no',], 'trim'],
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'video_banner_urls', 'banner_urls', 'unit', 'plugin_sign', 'goods_no', 'date', 'signing_head_img', 'signing_foot_img'], 'string'],
[['original_price', 'cost_price', 'price', 'goods_weight'], 'number'],
[['name', 'subtitle', 'detail', 'price', 'cover_pic', 'video_url', 'video_banner_urls', 'banner_urls', 'unit', 'plugin_sign', 'goods_no', 'date', 'signing_head_img', 'signing_foot_img'], 'string'],
[['original_price', 'cost_price', 'goods_weight'], 'number'],
[['type', 'use_attr', 'goods_stock', 'virtual_sales', 'confine_count', 'freight_id', 'sort', 'cx_mch_id'], 'integer'],
[['cat_id', 'cat1_id', 'cat2_id', 'cat3_id', 'cat4_id',], 'integer'],
[['pic_urls', 'cat_ids', 'model', 'attr', 'attrGroups'], 'safe'],
[['cost_price', 'original_price', 'price'], 'number', 'min' => 0],
[['cost_price', 'original_price', 'price'], 'number', 'max' => 9999999],
[['cost_price', 'original_price'], 'number', 'min' => 0],
[['cost_price', 'original_price'], 'number', 'max' => 9999999],
[['sort', 'virtual_sales', 'freight_id'], 'default', 'value' => 100],
[['confine_count', 'use_attr'], 'default', 'value' => 0],
[['name', 'price', 'cover_pic', 'type', 'plugin_sign', 'banner_urls', 'model', 'cx_mch_id'], 'required'],
@ -124,6 +124,7 @@ class CommonGoodsEditForm extends Model
$this->model->cx_mch_id = $this->cx_mch_id;
$this->model->plugin_sign = $this->plugin_sign;
}
$this->model->price = $this->price;
$this->model->goods_stock = empty($this->goods_stock) ? 9999 : $this->goods_stock; // 商品库存
$this->model->virtual_sales = $this->virtual_sales;
@ -185,8 +186,8 @@ class CommonGoodsEditForm extends Model
}
$goods_hub->name = $this->name;
$goods_hub->subtitle = $this->subtitle;
$goods_hub->original_price = $this->original_price ? $this->original_price : $this->price;
$goods_hub->cost_price = $this->cost_price ? $this->cost_price : $this->price;
// $goods_hub->original_price = $this->original_price ? $this->original_price : $this->price;
// $goods_hub->cost_price = $this->cost_price ? $this->cost_price : $this->price;
$goods_hub->detail = $this->detail;
$goods_hub->cover_pic = $this->cover_pic;
$goods_hub->signing_head_img = $this->signing_head_img;

View File

@ -154,7 +154,7 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="layui-form-item">
<label class="layui-form-label required">签约价格</label>
<div class="layui-input-inline">
<input type="number" name="price" placeholder="请输入售价" autocomplete="off"
<input type="subtitle" name="price" placeholder="请输入售价" autocomplete="off"
class="layui-input" value="<?= $model->price ?>" lay-verify="required">
</div>
<div class="layui-form-mid layui-word-aux"></div>