VideoGoodsForm.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\models\Order;
  9. use app\models\OrderDetail;
  10. use app\models\SaasUser;
  11. use app\models\User;
  12. use app\models\VideoGoodsShare;
  13. use yii\base\Model;
  14. class VideoGoodsForm extends Model
  15. {
  16. public $goods_name;
  17. public $name;
  18. public $mobile;
  19. public $status;
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function rules()
  24. {
  25. return [
  26. [['goods_name', 'name', 'mobile'], 'string'],
  27. [['status'], 'integer']
  28. ];
  29. }
  30. public function videoGoodsShareList()
  31. {
  32. try {
  33. $query = VideoGoodsShare::find()->alias('vgs')
  34. ->leftJoin(['u' => User::tableName()], 'vgs.author_user_id = u.id')
  35. ->leftJoin(['o' => Order::tableName()], 'vgs.order_id = o.id')
  36. ->leftJoin(['od' => OrderDetail::tableName()], 'vgs.order_detail = od.id')
  37. ->leftJoin(['su' => SaasUser::tableName()], 'u.binding = su.mobile')
  38. ->where(['vgs.store_id' => get_store_id()]);
  39. if ($this->goods_name) {
  40. $query->andWhere(['LIKE', 'od.goods_name', $this->goods_name]);
  41. }
  42. if ($this->name) {
  43. $query->andWhere(['LIKE', 'su.name', $this->name]);
  44. }
  45. if ($this->mobile) {
  46. $query->andWhere(['LIKE', 'su.mobile', $this->mobile]);
  47. }
  48. if ($this->status) {
  49. if ((int)$this->status === 1) {
  50. $query->andWhere(['is_send' => 1]);
  51. }
  52. if ((int)$this->status === 2) {
  53. $query->andWhere(['is_send' => 0]);
  54. }
  55. }
  56. $query->select('vgs.id, vgs.is_send, vgs.is_pay, vgs.num, vgs.created_at, vgs.send_time, su.name, su.mobile, su.avatar, o.order_no, od.goods_name, od.pic, vgs.profit, vgs.proportion');
  57. $query->orderBy(['vgs.created_at' => SORT_DESC]);
  58. $page = pagination_make($query);
  59. foreach ($page['list'] as &$item) {
  60. $item['is_send'] *= 1;
  61. $item['is_pay'] *= 1;
  62. $item['profit'] .= '%';
  63. }
  64. return [
  65. 'code' => 0,
  66. 'msg' => 'success',
  67. 'data' => [
  68. 'data' => $page['list'],
  69. 'pageNo' => $page['pageNo'],
  70. 'totalCount' => $page['totalCount']
  71. ]
  72. ];
  73. } catch (\Exception $e) {
  74. return [
  75. 'code' => 1,
  76. 'msg' => $e->getMessage()
  77. ];
  78. }
  79. }
  80. }