| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1\diy;
- use app\models\MchDiyTemplate;
- use app\utils\GetInfo;
- use yii\base\Model;
- class MchDiyTemplateForm extends Model
- {
- public $template_id;
- public $mch_id;
- public $page;
- public function rules()
- {
- return [
- [['template_id', 'mch_id'], 'integer']
- ];
- }
- public function detail()
- {
- if (!$this->validate()) {
- return $this->getErrorResponse();
- }
- $detail = MchDiyTemplate::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'id' => $this->template_id])->one();
- if (!$detail) {
- return [
- 'code' => 1,
- 'msg' => '模板不存在',
- ];
- }
- if ($detail) {
- $is_waimai = 0;
- $temp = ($detail['template'] == 'null' || !$detail['template']) ? [] : json_decode($detail['template'], true);
- MchDiyGoods::getTemplate($temp, $this->mch_id, get_store_id());
- $timeAll = [];
- foreach ($temp as $index => &$item) {
- switch ($item['type']) {
- case 'video':
- $res = GetInfo::getVideoInfo($item['param']['url']);
- if ($res && $res['code'] == 0) {
- $item['param']['url'] = $res['url'];
- }
- $item['param']['id'] = $index;
- break;
- case 'banner':
- foreach ($item['param']['list'] as &$value) {
- if ($value['open_type'] == 'wxapp') {
- $res = self::getUrl($value['page_url']);
- $value['appId'] = $res[2];
- $value['path'] = urldecode($res[4]);
- }
- }
- unset($value);
- $item['param']['banner_list'] = $item['param']['list'];
- break;
- case 'nav':
- $nav_arr = [];
- $nav = [];
- foreach ($item['param']['list'] as $k => &$v) {
- if ($k % ($item['param']['count'] * $item['param']['col']) == 0) {
- if (count($nav) > 0) {
- $nav_arr[] = $nav;
- }
- $nav = [];
- }
- $nav[] = $v;
- }
- if (count($nav) > 0) {
- $nav_arr[] = $nav;
- }
- $item['param']['nav_list'] = $nav_arr;
- $item['param']['is_slide'] = $item['param']['is_slide'] ? 'true' : 'false';
- break;
- case 'rubik':
- foreach ($item['param']['list'] as &$value) {
- if (isset($value['open_type']) && $value['open_type'] == 'wxapp') {
- $res = self::getUrl($value['url']);
- $value['appId'] = $res[2];
- $value['path'] = urldecode($res[4]);
- } else {
- if (strpos($value['url'], '?') === false) {
- $value['url'] = $value['url'] . '?mch_id=' . $this->mch_id;
- } else {
- $value['url'] = $value['url'] . '&mch_id=' . $this->mch_id;
- }
- }
- }
- unset($value);
- $item['param']['nav_list'] = $item['param']['list'];
- break;
- case 'link':
- if (isset($item['param']['open_type']) && $item['param']['open_type'] == 'wxapp') {
- $res = self::getUrl($item['param']['url']);
- $item['param']['appId'] = $res[2];
- $item['param']['path'] = urldecode($res[4]);
- } else {
- if (strpos($item['param']['url'], '?') === false) {
- $item['param']['url'] = $item['param']['url'] . '?mch_id=' . $this->mch_id;
- } else {
- $item['param']['url'] = $item['param']['url'] . '&mch_id=' . $this->mch_id;
- }
- }
- break;
- case 'goods':
- $param = &$item['param'];
- $list = [];
- foreach ($param['list'] as $key => &$value) {
- if ($value['cat_id'] && $param['list'][$key]['goods_style'] != 2) {
- $res = MchDiyGoods::getGoods($this->store, 'goods', [], $param['list'][$key]['cat_id'], 30, true);
- $goodsList = $res['goods_list'];
- if ($param['list'][$key]['goods_style'] == 1) {
- array_splice($goodsList, $param['list'][$key]['goods_num']);
- }
- $value['goods_list'] = $goodsList;
- }
- if (count($value['goods_list']) > 0) {
- $list[] = $value;
- }
- }
- $param['list'] = $list;
- break;
- case 'miaosha':
- $item['param']['buy_content'] = $item['param']['buy_content'] ? $item['param']['buy_content'] : '马上秒';
- $item['param']['type_name'] = '秒杀';
- $newList = [];
- foreach ($item['param']['list'] as &$value) {
- $goodsList = [];
- foreach ($value['goods_list'] as $k => $v) {
- $startTime = strtotime($v['open_date'] . ' ' . $v['start_time'] . ':00:00');
- if ($startTime >= time()) {
- $v['is_start'] = 0;
- $v['time'] = $startTime - time();
- $v['time_end'] = $startTime - time() + 3600;
- $v['time_content'] = $item['param']['list_style'] == 1 ? "活动未开始" : "距开始仅剩";
- } else if ($startTime <= time() && $startTime + 3600 >= time()) {
- $v['is_start'] = 1;
- $v['time'] = $startTime - time() + 3600;
- $v['time_content'] = $item['param']['list_style'] == 1 ? "仅剩" : "距结束仅剩";
- } else {
- $v['is_start'] = 1;
- $v['time'] = 0;
- $v['time_content'] = "已结束";
- continue;
- }
- $goodsList[] = $v;
- }
- if (count($goodsList) > 0) {
- $value['goods_list'] = $goodsList;
- $newList[] = $value;
- }
- }
- $item['param']['list'] = $newList;
- unset($value);
- if (count($item['param']['list']) > 0) {
- $timeAll['miaosha_' . $index] = $item;
- }
- break;
- case 'pintuan':
- $item['param']['buy_content'] = $item['param']['buy_content'] ? $item['param']['buy_content'] : '去拼团';
- $item['param']['type_name'] = '拼团';
- if (count($item['param']['list']) > 0) {
- $timeAll['pintuan_' . $index] = $item;
- }
- break;
- case 'book':
- $item['param']['buy_content'] = $item['param']['buy_content'] ? $item['param']['buy_content'] : '预约';
- break;
- case 'bargain':
- $item['param']['buy_content'] = $item['param']['buy_content'] ? $item['param']['buy_content'] : '去参与';
- $item['param']['type_name'] = '砍价';
- $newList = [];
- foreach ($item['param']['list'] as &$value) {
- $goodsList = [];
- foreach ($value['goods_list'] as $k => $v) {
- $startTime = $v['begin_time'];
- $endTime = $v['end_time'];
- if ($startTime >= time()) {
- $v['is_start'] = 0;
- $v['time'] = $startTime - time();
- $v['time_end'] = $endTime - time();
- $v['time_content'] = $item['param']['list_style'] == 1 ? "活动未开始" : "距开始仅剩";
- } else if ($startTime <= time() && $endTime >= time()) {
- $v['is_start'] = 1;
- $v['time'] = $endTime - time();
- $v['time_content'] = $item['param']['list_style'] == 1 ? "仅剩" : "距结束仅剩";
- } else {
- $v['is_start'] = 1;
- $v['time'] = 0;
- $v['time_content'] = "已结束";
- continue;
- }
- $goodsList[] = $v;
- }
- if (count($goodsList) > 0) {
- $value['goods_list'] = $goodsList;
- $newList[] = $value;
- }
- }
- $item['param']['list'] = $newList;
- unset($value);
- if (count($item['param']['list']) > 0) {
- $timeAll['bargain_' . $index] = $item;
- }
- break;
- case 'waimai':
- $param = &$item['param'];
- $list = [];
- foreach ($param['list'] as $key => &$value) {
- if ($value['cat_id'] && $param['list'][$key]['goods_style'] != 2) {
- $res = MchDiyGoods::getGoods($this->store, 'waimai', [], $param['list'][$key]['cat_id'], 30, true);
- $goodsList = $res['goods_list'];
- if ($param['list'][$key]['goods_style'] == 1) {
- array_splice($goodsList, $param['list'][$key]['goods_num']);
- }
- $value['goods_list'] = $goodsList;
- }
- if (count($value['goods_list']) > 0) {
- $list[] = $value;
- }
- $param['list'][$key]['cat_goods_num'] = 0;
- }
- $param['list'] = $list;
- $is_waimai =1;
- break;
- default:
- break;
- }
- }
- unset($item);
- return [
- 'code' => 0,
- 'msg' => '请求成功',
- 'data' => [
- 'template' => $temp,
- 'act_modal_list' => [],
- 'info' => $this->page->title,
- 'page_id' => $this->page->id,
- 'status' => 'diy',
- 'time_all' => $timeAll,
- 'is_waimai' =>$is_waimai,
- ]
- ];
- }
- }
- public static function getUrl($url)
- {
- preg_match('/^[^\?+]\?([\w|\W]+)=([\w|\W]*?)&([\w|\W]+)=([\w|\W]*?)$/', $url, $res);
- return $res;
- }
- }
|