PondLogForm.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\modules\client\models\v1\pond;
  3. use app\constants\OptionSetting;
  4. use app\models\Option;
  5. use app\models\PondLog;
  6. use yii\base\Model;
  7. use yii\data\Pagination;
  8. class PondLogForm extends Model
  9. {
  10. public $user_id;
  11. public $store_id;
  12. public $page;
  13. public $limit;
  14. public $id;
  15. public function search()
  16. {
  17. $form = PondLog::find()
  18. ->where([
  19. 'store_id' => $this->store_id,
  20. 'user_id' => $this->user_id,
  21. 'is_delete' => 0,
  22. ])->andWhere(['<>', 'type', '1'])
  23. ->with(['gift' => function ($query) {
  24. $query->where([
  25. 'store_id' => $this->store_id,
  26. 'is_delete' => 0
  27. ]);
  28. }]);
  29. $count = $form->count();
  30. $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  31. $list = $form->limit($pagination->limit)->offset($pagination->offset)->orderBy('create_time DESC,id DESC')->asArray()->all();
  32. foreach ($list as &$v) {
  33. $v['type'] = (int)$v['type'];
  34. $v['create_time'] = date('Y:m:d H:i:s', $v['create_time']);
  35. switch ($v['type']) {
  36. case 2:
  37. $v['name'] = $v['gift']['name'];
  38. break;
  39. case 1:
  40. $v['name'] = '谢谢参与';
  41. break;
  42. default:
  43. }
  44. }
  45. unset($v);
  46. $kf_wechat_img = Option::get(OptionSetting::WEB_KF_WECHAT_IMG, $this->store_id, 'display')['value'];
  47. if ($list) {
  48. return [
  49. 'code' => 0,
  50. 'data' => [
  51. 'kf_wechat_img' => $kf_wechat_img,
  52. 'list' => $list,
  53. ]
  54. ];
  55. } else {
  56. return [
  57. 'code' => 0,
  58. 'data' => [
  59. 'list' => []
  60. ],
  61. ];
  62. }
  63. }
  64. public function del()
  65. {
  66. $log = PondLog::findOne([
  67. 'id' => $this->id,
  68. 'store_id' => $this->store_id,
  69. 'user_id' => $this->user_id,
  70. 'is_delete' => 0,
  71. ]);
  72. if (!$log) {
  73. return [
  74. 'code' => 1,
  75. 'msg' => '网络异常'
  76. ];
  77. }
  78. $log->is_delete = 1;
  79. if ($log->save()) {
  80. return [
  81. 'code' => 0,
  82. 'msg' => '删除成功'
  83. ];
  84. }
  85. return [
  86. 'code' => 1,
  87. 'msg' => '网络异常'
  88. ];
  89. }
  90. }