PoolForm.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace app\modules\admin\models\integralAppreciation;
  3. use app\models\Goods;
  4. use app\models\IntegralAppreciationGoods;
  5. use app\models\IntegralAppreciationPool;
  6. use app\models\IntegralAppreciationPoolSub;
  7. use app\models\IntegralAppreciationUser;
  8. use app\models\IntegralAppreciationUserIntegralLog;
  9. use app\models\Order;
  10. use app\models\OrderDetail;
  11. use app\models\User;
  12. use yii\base\Model;
  13. class PoolForm extends Model
  14. {
  15. public $store_id;
  16. public $mobile;
  17. public $order_no;
  18. public $user_name;
  19. public $start_time;
  20. public $end_time;
  21. public $id;
  22. public $type;
  23. public function rules()
  24. {
  25. return [
  26. [['store_id', 'id', 'type'], 'integer'],
  27. [['mobile', 'user_name', 'start_time', 'end_time', 'order_no'], 'string']
  28. ];
  29. }
  30. public function attributeLabels()
  31. {
  32. return [
  33. 'store_id' => '商城ID',
  34. 'mobile' => '订单编号',
  35. 'user_name' => '用户名称',
  36. 'order_no' => '订单编号',
  37. 'start_time' => '',
  38. 'end_time' => '',
  39. ];
  40. }
  41. /**
  42. * 列表
  43. */
  44. public function getIntegralList() {
  45. $store_id = $this->store_id;
  46. $mobile = $this->mobile;
  47. $start_time = $this->start_time;
  48. $end_time = $this->end_time;
  49. $user_name = $this->user_name;
  50. $query = IntegralAppreciationUser::find()->alias('iu')
  51. ->leftJoin(['u' => User::tableName()], 'iu.user_id = u.id')
  52. ->where(['iu.store_id' => $store_id]);
  53. if ($mobile) {
  54. $query->andWhere(['like', 'u.binding', $mobile]);
  55. }
  56. if ($user_name) {
  57. $query->andWhere(['like', 'u.nickname', $user_name]);
  58. }
  59. if ($start_time) {
  60. $start_time = strtotime($start_time);
  61. $query->andWhere(['>=', 'iu.created_at', $start_time]);
  62. }
  63. if ($end_time) {
  64. $end_time = strtotime($end_time);
  65. $query->andWhere(['<=', 'iu.created_at', $end_time]);
  66. }
  67. $query->orderBy('iu.id DESC')
  68. ->select('iu.id, iu.integral total_integral, u.binding mobile, u.avatar_url avatar, u.nickname, iu.created_at');
  69. $list = pagination_make($query);
  70. foreach ($list['list'] as &$item) {
  71. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  72. }
  73. return [
  74. 'code' => 0,
  75. 'msg' => '',
  76. 'data' => $list
  77. ];
  78. }
  79. /**
  80. * 积分明细
  81. */
  82. public function getIntegralDetail() {
  83. $id = $this->id;
  84. $type = $this->type;
  85. $query = IntegralAppreciationUserIntegralLog::find()->where(['integral_user_id' => $id]);
  86. if (isset($type) && in_array($type, [IntegralAppreciationUserIntegralLog::TYPE_INCOME, IntegralAppreciationUserIntegralLog::TYPE_EXPEND])) {
  87. $query->andWhere(['type' => $type]);
  88. }
  89. $start_time = $this->start_time;
  90. $end_time = $this->end_time;
  91. if ($start_time) {
  92. $start_time = strtotime($start_time);
  93. $query->andWhere(['>=', 'created_at', $start_time]);
  94. }
  95. if ($end_time) {
  96. $end_time = strtotime($end_time);
  97. $query->andWhere(['<=', 'created_at', $end_time]);
  98. }
  99. $query->orderBy('id desc')->select('id, amount, type, source_type, desc, created_at');
  100. $list = pagination_make($query);
  101. foreach ($list['list'] as &$item) {
  102. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  103. $item['type'] = intval($item['type']);
  104. $item['source_type'] = intval($item['source_type']);
  105. $item['source_type_text'] = IntegralAppreciationUserIntegralLog::$source_type_desc[$item['source_type']];
  106. }
  107. return [
  108. 'code' => 0,
  109. 'msg' => '',
  110. 'data' => $list
  111. ];
  112. }
  113. public function getAmountList() {
  114. $store_id = $this->store_id;
  115. $mobile = $this->mobile;
  116. $order_no = $this->order_no;
  117. $start_time = $this->start_time;
  118. $end_time = $this->end_time;
  119. $user_name = $this->user_name;
  120. $query = IntegralAppreciationPoolSub::find()->alias('ps')
  121. ->leftJoin(['u' => User::tableName()], 'ps.user_id = u.id')
  122. ->leftJoin(['o' => Order::tableName()], 'ps.order_id = o.id AND ps.reflux_type = ' . IntegralAppreciationPoolSub::REFLUX_TYPE_ORDER)
  123. ->where(['ps.store_id' => $store_id]);
  124. // ->andWhere(['>', 'ps.amount', '0']);
  125. if ($mobile) {
  126. $query->andWhere(['like', 'u.binding', $mobile]);
  127. }
  128. if ($user_name) {
  129. $query->andWhere(['like', 'u.nickname', $user_name]);
  130. }
  131. if ($order_no) {
  132. $query->andWhere(['like', 'o.order_no', $order_no]);
  133. }
  134. if ($start_time) {
  135. $start_time = strtotime($start_time);
  136. $query->andWhere(['>=', 'ps.created_at', $start_time]);
  137. }
  138. if ($end_time) {
  139. $end_time = strtotime($end_time);
  140. $query->andWhere(['<=', 'ps.created_at', $end_time]);
  141. }
  142. $query->orderBy('ps.id DESC')
  143. ->select('ps.id, ps.amount, ps.order_id, o.order_no, ps.reflux_type, ps.created_at,
  144. u.binding mobile, u.avatar_url avatar, u.nickname, o.order_no');
  145. $list = pagination_make($query);
  146. foreach ($list['list'] as &$item) {
  147. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  148. $item['reflux_type'] = intval($item['reflux_type']);
  149. if ($item['reflux_type'] === IntegralAppreciationPoolSub::REFLUX_TYPE_WITHDRAW) {
  150. $item['order_no'] = $item['order_id'];
  151. }
  152. $item['reflux_type_text'] = IntegralAppreciationPoolSub::$reflux_type_text[$item['reflux_type']];
  153. }
  154. return [
  155. 'code' => 0,
  156. 'msg' => '',
  157. 'data' => $list
  158. ];
  159. }
  160. public function totalAmount() {
  161. $store_id = $this->store_id;
  162. $pool = IntegralAppreciationPool::findOne(['store_id' => $store_id]);
  163. // $total_integral = IntegralAppreciationUser::find()->where(['store_id' => $store_id])->sum('integral') ?: 0;
  164. return [
  165. 'code' => 0,
  166. 'msg' => '',
  167. 'data' => [
  168. 'amount' => $pool->amount ?? '0.00',
  169. 'total_integral' => $pool->total_integral ?? '0.00',
  170. 'integral_price' => $pool->integral_price ?? '0.00',
  171. ]
  172. ];
  173. }
  174. }