| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\models;
- use app\models\NewDiyTemplate;
- use yii\base\Model;
- use yii\helpers\Json;
- use yii\data\Pagination;
- use app\models\Store;
- use app\models\Goods;
- use app\models\GoodsBook;
- use app\models\GoodsCat;
- use app\models\Cat;
- use app\models\WechatConfig;
- use app\models\Option;
- class NewDiyForm extends Model
- {
- private $alliance_store_id = 0; //联盟店铺id=0
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [[]]
- ];
- }
- public function attributeLabels()
- {
- return [
- ];
- }
- /**
- * 获取商品列表
- */
- public static function getGoods($reqeruy)
- {
- $goods_id = $reqeruy['goods_id'];
- if(is_string($goods_id) && $goods_id != ''){
- $goods_id = explode(',', $goods_id);
- }
- $goods_id = (array)$goods_id;
- $query = Goods::find()->alias('g')->leftJoin(['s' => Store::tableName()], 'g.store_id = s.id')
- ->where([
- 'g.is_delete' => 0,
- 'g.status' => 1
- ])->andWhere(['not like', 'g.name', '当面付']);
- if ($reqeruy['store_id'] > -1) {
- $query->andWhere(['g.store_id' => $reqeruy['store_id'], 's.is_delete' => 0]);
- }
- if (isset($reqeruy['product_type']) && $reqeruy['product_type']) {
- $query->andWhere(['g.product_type' => $reqeruy['product_type']]);
- }
- if (!empty($goods_id)) {
- $query->andWhere([
- 'in', 'g.id', $goods_id
- ]);
- $query->orderBy([new \yii\db\Expression('FIELD(g.id, :ids)')]);
- $query->addParams([':ids' => implode(',', array_map(function($id) {
- return (int)$id;
- }, $goods_id))]);
- } else {
- if ($reqeruy['cat_id']) {
- if ($reqeruy['product_type'] == 2) {
- $query->andWhere(['g.id' => \app\models\BookingGoodsExt::find()->where(['cat_id' => $reqeruy['cat_id']])->select('goods_id')]);
- }else{
- $query->leftJoin(['gc' => GoodsCat::tableName()], 'gc.goods_id=g.id')
- ->andWhere(['gc.cat_id' => Cat::getCatId($reqeruy['cat_id'])])->groupBy('gc.goods_id');
- }
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $reqeruy['limit'], 'page' => $reqeruy['page'] - 1]);
- $query->orderBy(['g.sort' => SORT_DESC, 'g.id' => SORT_DESC]);
- }
- //$query->leftJoin(['s' => Store::tableName()], 's.id=g.store_id')->andWhere(['s.is_delete'=>0]);
- //$select = ['g.goods_num', 'g.status', 'g.product_type', 'g.virtual_sales', 'g.name', 'g.id', 'g.service', 'g.attr', 'g.cover_pic', 'g.attr', 'g.use_attr', 'g.price', 'g.original_price','g.store_id','s.name store_name','s.business_model'];
- $select = ['g.goods_num', 'g.status', 'g.product_type', 'g.virtual_sales', 'g.name', 'g.id', 'g.service', 'g.attr', 'g.cover_pic', 'g.attr', 'g.use_attr', 'g.price', 'g.original_price','g.store_id', 'g.integral_price', 'g.goods_take_price', 'g.goods_send_profit'];
- $goods_list = $query->groupBy('g.id')->select($select)->asArray()->all();
- foreach ($goods_list as $key => $value) {
- $goods = Goods::findOne($value['id']);
- $goods_list[$key]['virtual_sales'] = $goods->getSalesVolume() + $value['virtual_sales'];
- if ($value['product_type'] == 1) {
- $goods_list[$key]['date_book'] = Json::decode(GoodsBook::findOne(['goods_id' => $value['id']])->date_book);
- }
- if ($value['product_type'] == 2) {
- $goods_list[$key]['service_book'] = Json::decode(GoodsBook::findOne(['goods_id' => $value['id']])->service_book);
- }
- $goods_list[$key]['storeInfo'] = [
- 'id' => '0',
- 'name' => Option::get('name', 0, 'saas', '平台运营')['value'],
- 'logo' => Option::get('logo', 0, 'saas', '')['value'],
- 'coordinate' => '',
- 'created_at' => '',
- 'category_id' => '',
- 'tags' => '',
- 'sales' => '',
- 'rank' => '',
- 'per_spend' => '',
- 'business_model' => '',
- 'address' => '',
- 's_time' => '00:00',
- 'e_time' => '23:59'
- ];
- $goods_list[$key]['take_price'] = 0;
- $goods_list[$key]['send_price'] = 0;
- if ($value['goods_take_price'] > 0) {
- $goods_list[$key]['take_price'] = \round($value['price'] * $value['goods_take_price'] / 100, 2);
- }
- if ($value['goods_send_profit'] > 0) {
- $goods_list[$key]['send_price'] = \round($value['price'] * $value['goods_send_profit'] / 100, 2);
- }
- if($value['store_id'] > 0){
- $goods_list[$key]['storeInfo'] = Store::find()->where(['id'=>$value['store_id'],'is_delete'=>0])->select(['id', 'name', 'logo', 'coordinate', 'created_at', 'category_id', 'tags', 'sales', 'rank', 'per_spend','business_model','address', 's_time', 'e_time'])->asArray()->one();
- $wechatInfo = WechatConfig::find()->where(['store_id'=>$value['store_id'],'is_delete'=>0,'type'=>1])->asArray()->one();
- if(isset($goods_list[$key]['storeInfo']['id']) && $goods_list[$key]['storeInfo']['id']>0){
- if($wechatInfo){
- $goods_list[$key]['storeInfo']['wechat_app_id'] = $wechatInfo['app_id'];
- $goods_list[$key]['storeInfo']['gh_wechat_app_id'] = $wechatInfo['gh_wechat_app_id'];
- }
- $alipayInfo = Option::get('alipay_config',$value['store_id'],'alipay');
- if($alipayInfo && $alipayInfo['value']){
- $alipayInfo = json_decode($alipayInfo['value'],true);
- $goods_list[$key]['storeInfo']['alipay_app_id'] = $alipayInfo['app_id'];
- }
- }
- }
- }
- return [
- 'code' => 0,
- 'data' => [
- 'row_count' => isset($count) ? $count: 0,
- 'page_count' => isset($pagination) ? $pagination->pageCount : 0,
- 'list' => $goods_list
- ]
- ];
- }
- /**
- * 新diy
- * @return array
- */
- public function saveNewTemplate()
- {
- $template = post_params('template');
- if ($template == '{}') {
- return [
- 'code' => 1,
- 'msg' => '保存模板数据为空'
- ];
- }
- $controls = post_params('controls');
- $id = post_params('id', 0);
- $name = post_params('name', "DIY");
- $type = post_params('type', 0);
- $form = NewDiyTemplate::findOne(['store_id' => $this->alliance_store_id, 'is_delete' => 0, 'id' => $id]) ?: new NewDiyTemplate();
- $form->store_id = $this->alliance_store_id;
- $form->name = $name;
- $form->template = $template;
- $form->is_delete = 0;
- $form->addtime = time();
- $form->type = $type;
- if ($form->save()) {
- // 保存控件
- if ($controls) {
- self::saveControls($controls);
- }
- return [
- 'code' => 0,
- 'msg' => '保存成功',
- 'data' => [
- 'template' => $form,
- 'controls' => NewDiyTemplate::find()
- ->where([
- 'store_id' => $this->alliance_store_id,
- 'is_delete' => 0,
- 'type' => 100
- ])->asArray()->one()['template']
- ]
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => $form->errors
- ];
- }
- }
- public function saveControls($controls)
- {
- // controls type=100
- $controlsDiy = NewDiyTemplate::findOne(['store_id' => $this->alliance_store_id, 'is_delete' => 0, 'type' => 100]) ?: new NewDiyTemplate();
- $controlsDiy->store_id = $this->alliance_store_id;
- $controlsDiy->name = 'controls';
- $controlsDiy->template = $controls;
- $controlsDiy->is_delete = 0;
- $controlsDiy->addtime = time();
- $controlsDiy->type = 100;
- $controlsDiy->save();
- }
- public function getNewTemplateList()
- {
- $query = NewDiyTemplate::find()
- ->where([
- 'store_id' => $this->alliance_store_id,
- 'is_delete' => 0,
- ]);
- $list = $query->andWhere(['!=', 'type', 100])->orderBy(['id' => SORT_ASC])->asArray()->all();
- return [
- 'code' => 0,
- 'msg' => '加载成功',
- 'data' => [
- 'list' => $list,
- 'controls' => NewDiyTemplate::find()
- ->where([
- 'store_id' => $this->alliance_store_id,
- 'is_delete' => 0,
- 'type' => 100
- ])->asArray()->one()['template']
- ]
- ];
- }
- }
|