| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- namespace app\modules\admin\models\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\Order;
- use app\models\OrderDetail;
- use app\models\User;
- use yii\base\Model;
- class PoolForm extends Model
- {
- public $store_id;
- public $mobile;
- public $order_no;
- public $user_name;
- public $start_time;
- public $end_time;
- public $id;
- public $type;
- public function rules()
- {
- return [
- [['store_id', 'id', 'type'], 'integer'],
- [['mobile', 'user_name', 'start_time', 'end_time', 'order_no'], 'string']
- ];
- }
- public function attributeLabels()
- {
- return [
- 'store_id' => '商城ID',
- 'mobile' => '订单编号',
- 'user_name' => '用户名称',
- 'order_no' => '订单编号',
- 'start_time' => '',
- 'end_time' => '',
- ];
- }
- /**
- * 列表
- */
- public function getIntegralList() {
- $store_id = $this->store_id;
- $mobile = $this->mobile;
- $start_time = $this->start_time;
- $end_time = $this->end_time;
- $user_name = $this->user_name;
- $query = IntegralAppreciationUser::find()->alias('iu')
- ->leftJoin(['u' => User::tableName()], 'iu.user_id = u.id')
- ->where(['iu.store_id' => $store_id]);
- if ($mobile) {
- $query->andWhere(['like', 'u.binding', $mobile]);
- }
- if ($user_name) {
- $query->andWhere(['like', 'u.nickname', $user_name]);
- }
- if ($start_time) {
- $start_time = strtotime($start_time);
- $query->andWhere(['>=', 'iu.created_at', $start_time]);
- }
- if ($end_time) {
- $end_time = strtotime($end_time);
- $query->andWhere(['<=', 'iu.created_at', $end_time]);
- }
- $query->orderBy('iu.id DESC')
- ->select('iu.id, iu.integral total_integral, u.binding mobile, u.avatar_url avatar, u.nickname, iu.created_at');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- /**
- * 积分明细
- */
- public function getIntegralDetail() {
- $id = $this->id;
- $type = $this->type;
- $query = IntegralAppreciationUserIntegralLog::find()->where(['integral_user_id' => $id]);
- if (isset($type) && in_array($type, [IntegralAppreciationUserIntegralLog::TYPE_INCOME, IntegralAppreciationUserIntegralLog::TYPE_EXPEND])) {
- $query->andWhere(['type' => $type]);
- }
- $start_time = $this->start_time;
- $end_time = $this->end_time;
- if ($start_time) {
- $start_time = strtotime($start_time);
- $query->andWhere(['>=', 'created_at', $start_time]);
- }
- if ($end_time) {
- $end_time = strtotime($end_time);
- $query->andWhere(['<=', 'created_at', $end_time]);
- }
- $query->orderBy('id desc')->select('id, amount, type, source_type, desc, created_at');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['type'] = intval($item['type']);
- $item['source_type'] = intval($item['source_type']);
- $item['source_type_text'] = IntegralAppreciationUserIntegralLog::$source_type_desc[$item['source_type']];
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- public function getAmountList() {
- $store_id = $this->store_id;
- $mobile = $this->mobile;
- $order_no = $this->order_no;
- $start_time = $this->start_time;
- $end_time = $this->end_time;
- $user_name = $this->user_name;
- $query = IntegralAppreciationPoolSub::find()->alias('ps')
- ->leftJoin(['u' => User::tableName()], 'ps.user_id = u.id')
- ->leftJoin(['o' => Order::tableName()], 'ps.order_id = o.id AND ps.reflux_type = ' . IntegralAppreciationPoolSub::REFLUX_TYPE_ORDER)
- ->where(['ps.store_id' => $store_id]);
- // ->andWhere(['>', 'ps.amount', '0']);
- if ($mobile) {
- $query->andWhere(['like', 'u.binding', $mobile]);
- }
- if ($user_name) {
- $query->andWhere(['like', 'u.nickname', $user_name]);
- }
- if ($order_no) {
- $query->andWhere(['like', 'o.order_no', $order_no]);
- }
- if ($start_time) {
- $start_time = strtotime($start_time);
- $query->andWhere(['>=', 'ps.created_at', $start_time]);
- }
- if ($end_time) {
- $end_time = strtotime($end_time);
- $query->andWhere(['<=', 'ps.created_at', $end_time]);
- }
- $query->orderBy('ps.id DESC')
- ->select('ps.id, ps.amount, ps.order_id, o.order_no, ps.reflux_type, ps.created_at,
- u.binding mobile, u.avatar_url avatar, u.nickname, o.order_no');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['reflux_type'] = intval($item['reflux_type']);
- if ($item['reflux_type'] === IntegralAppreciationPoolSub::REFLUX_TYPE_WITHDRAW) {
- $item['order_no'] = $item['order_id'];
- }
- $item['reflux_type_text'] = IntegralAppreciationPoolSub::$reflux_type_text[$item['reflux_type']];
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- public function totalAmount() {
- $store_id = $this->store_id;
- $pool = IntegralAppreciationPool::findOne(['store_id' => $store_id]);
- // $total_integral = IntegralAppreciationUser::find()->where(['store_id' => $store_id])->sum('integral') ?: 0;
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- 'amount' => $pool->amount ?? '0.00',
- 'total_integral' => $pool->total_integral ?? '0.00',
- 'integral_price' => $pool->integral_price ?? '0.00',
- ]
- ];
- }
- }
|