| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- namespace app\modules\client\models\v1\integralAppreciation;
- use app\models\Goods;
- use app\models\IntegralAppreciationGoods;
- use app\models\IntegralAppreciationPool;
- use app\models\IntegralAppreciationPoolSub;
- use app\models\IntegralAppreciationUser;
- use app\models\IntegralAppreciationUserIntegralLog;
- use app\models\Option;
- class IndexForm extends \yii\base\Model
- {
- public $store_id;
- public $user;
- public $type;
- //近一月
- const TYPE_MONTH = 0;
- //近半年
- const TYPE_HALF_YEAR = 1;
- //近一年
- const TYPE_YEAR = 2;
- //近三年
- const TYPE_THREE_YEAR = 3;
- public static $typeArray = [
- self::TYPE_MONTH => '近一月',
- self::TYPE_HALF_YEAR => '近半年',
- self::TYPE_YEAR => '近一年',
- self::TYPE_THREE_YEAR => '近三年',
- ];
- public function rules()
- {
- return [
- [['store_id', 'type'], 'integer'],
- [['type'], 'in', 'range' => [
- self::TYPE_MONTH,
- self::TYPE_HALF_YEAR,
- self::TYPE_YEAR,
- self::TYPE_THREE_YEAR,
- ]],
- ];
- }
- //首页数据
- public function index() {
- try {
- $user = $this->user;
- $store_id = $this->store_id;
- $type = $this->type;
- $integral_appreciation_setting = Option::get('integral_appreciation_setting', $store_id, 'integral_appreciation')['value'];
- $integral_appreciation_setting = json_decode($integral_appreciation_setting ?? '', true);
- //展示增值积分
- $integralAppreciationUser = IntegralAppreciationUser::findOne(['user_id' => $user->id]);
- $pool = IntegralAppreciationPool::findOne(['store_id' => $store_id]);
- $query = IntegralAppreciationPoolSub::find()->where([
- 'store_id' => $store_id
- ])->select([
- 'month' => new \yii\db\Expression("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y/%m/%d')"),
- 'integral_price' => new \yii\db\Expression('ROUND(max(after_integral_price), 2)')
- ]);
- switch ($type) {
- case self::TYPE_HALF_YEAR:
- $start_time = strtotime('-6 month');
- break;
- case self::TYPE_YEAR:
- $start_time = strtotime('-1 year');
- break;
- case self::TYPE_THREE_YEAR:
- $start_time = strtotime('-3 year');
- break;
- default:
- $start_time = strtotime('-1 month');
- break;
- }
- $end_time = time();
- $query->andWhere(['>=', 'created_at', $start_time]);
- $query->andWhere(['<=', 'created_at', $end_time]);
- $dateData_ = $query->groupBy('month')->orderBy('id ASC')->asArray()->all();
- $dateData = [
- 'categories' => array_column($dateData_, 'month'),
- 'series' => [[
- 'name' => '价格',
- 'data' => array_column($dateData_, 'integral_price'),
- ]]
- ];
- $baseUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl;
- $data = [
- 'user_info' => [
- 'avatar' => $user->avatar_url,
- 'nickname' => $user->nickname,
- ],
- 'integral' => $integralAppreciationUser->integral,
- 'price_change_log' => $dateData,
- 'today_integral_price' => $pool->integral_price ?? ($integral_appreciation_setting['integral_init_price'] ?: 0),
- 'today' => date('Y/m/d'),
- 'type' => self::$typeArray,
- 'integral_project_name' => $integral_appreciation_setting['integral_project_name'] ?: '增值积分中心',
- 'integral_bg' => $integral_appreciation_setting['integral_bg'] ?: $baseUrl . '/web/v1/statics/clientImg/integral_appreciation/integral_bg.png',
- 'integral_custom_name' => $integral_appreciation_setting['integral_custom_name'] ?: '增值积分',
- 'integral_appreciation_setting'=>$integral_appreciation_setting
- ];
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $data
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //商品列表
- public function goodsList() {
- $store_id = $this->store_id;
- $query = IntegralAppreciationGoods::find()->alias('ig')
- ->leftJoin(['g' => Goods::tableName()], 'ig.goods_id = g.id')
- ->where(['ig.is_delete' => 0, 'g.is_delete' => 0, 'ig.store_id' => $store_id]);
- $query->orderBy('ig.id DESC')
- ->select('ig.id, ig.goods_id, g.name, g.cover_pic, g.price, ig.reflux_amount');
- $list = pagination_make($query);
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- }
|