133 lines
4.5 KiB
PHP
133 lines
4.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年10月12日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\models\common\integral\mall;
|
|
|
|
use app\models\common\CommonGoodsListForm;
|
|
use app\models\integral\mall\IntegralMallGoods;
|
|
use app\models\integral\mall\IntegralMallGoodsAttr;
|
|
use app\models\integral\Integral;
|
|
use app\models\Goods;
|
|
use app\models\Cat;
|
|
use app\models\Model;
|
|
use app\components\SiteHelper;
|
|
use app\components\SysConst;
|
|
use app\components\Serializer;
|
|
use app\components\FlashStorage;
|
|
|
|
|
|
class CommonIntegralMallActionForm extends Model
|
|
{
|
|
public $cx_mch_id;
|
|
public $goods_id;
|
|
public $user_id;
|
|
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['cx_mch_id','warehouse_id'], 'integer'],
|
|
[['cx_mch_id'], 'required'],
|
|
[['goods_id'], 'required', 'on' => 'detail'],
|
|
[['user_id'], 'required', 'on' => 'index'],
|
|
];
|
|
}
|
|
|
|
public function getTree()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$cat_list = Cat::find()
|
|
->where([
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'is_delete' => 0,
|
|
'type' => Cat::TYPE_INTEGRAL_GOODS
|
|
])
|
|
->select('id,name,parent_id')
|
|
->orderBy(['sort' => SORT_ASC, 'created_at' => SORT_DESC])
|
|
->asArray()->all();
|
|
$data = [];
|
|
foreach($cat_list as $index => $item){
|
|
$item['goods_list'] = $this->getGoodsList($item['id']);
|
|
$data[] = $item;
|
|
}
|
|
return $this->apiReturnSuccess('ok', $data);
|
|
}
|
|
|
|
private function getGoodsList($cat_id)
|
|
{
|
|
$form = new CommonIntegralMallGoodsListForm();
|
|
$form->limit = 9999;
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->status = Goods::STATUS_ONLINE;
|
|
$form->plugin_sign = SysConst::$cxPluginSceneIntegralMall;
|
|
$form->cat_id = $cat_id;
|
|
$form->setFields('g.id,g.price,g.goods_stock,g.virtual_sales,g.sort,g.created_at,g.payment_people,g.payment_amount,g.payment_num,g.payment_order,g.sales,g.viewed_count,gh.name,gh.cover_pic,gh.unit,gh.type,img.integral_num');
|
|
$res = $form->search();
|
|
return $res['code'] == 0 ? $res['data'] : [];
|
|
}
|
|
|
|
|
|
//商品详情
|
|
public function getGoodsdetail()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$form = new CommonIntegralMallGoodsListForm();
|
|
$form->scenario = 'detail';
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->goods_id = $this->goods_id;
|
|
$form->status = Goods::STATUS_ONLINE;
|
|
$form->plugin_sign = SysConst::$cxPluginSceneIntegralMall;
|
|
$form->setFields('g.id,g.price,g.goods_stock,g.virtual_sales,g.sort,g.created_at,g.payment_people,g.payment_amount,g.payment_num,g.payment_order,g.sales,g.viewed_count,g.use_attr,g.attr_groups,g.confine_count,g.freight_id,gh.name,gh.subtitle,gh.original_price,gh.cost_price,gh.detail,gh.cover_pic,gh.pic_urls,gh.video_url,gh.unit,gh.type,img.integral_num');
|
|
$res = $form->search();
|
|
if($res['code'] != 0)
|
|
return $res;
|
|
if(count($res['data']) == 0){
|
|
return $this->apiReturnError('商品不存在或已经下线');
|
|
}
|
|
Goods::handleViewEvent($this->goods_id, $this->cx_mch_id);
|
|
$data = $res['data'][0];
|
|
return $this->apiReturnSuccess('ok', $data);
|
|
}
|
|
|
|
//首页
|
|
public function getIndex()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$data = [];
|
|
//账户积分信息
|
|
$integral = Integral::findOne(['user_id' => $this->user_id, 'is_delete' => 0, 'scene' => Integral::SCENARIO_DEFAULT]);
|
|
if($integral == null){
|
|
$data['account_integral'] = 0;
|
|
$data['account_total_integral'] = 0;
|
|
} else {
|
|
$data['account_integral'] = $integral->account_integral;
|
|
$data['account_total_integral'] = $integral->account_total_integral;
|
|
}
|
|
$data['cat_list'] = Cat::find()
|
|
->where([
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'is_delete' => 0,
|
|
'type' => Cat::TYPE_INTEGRAL_GOODS
|
|
])
|
|
->select('id,name,parent_id')
|
|
->orderBy(['sort' => SORT_ASC, 'created_at' => SORT_DESC])
|
|
->asArray()->all();
|
|
return $this->apiReturnSuccess('ok', $data);
|
|
}
|
|
}
|
|
|