MchSettingForm.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * @Author: your name
  9. * @Date: 2021-05-08 17:30:13
  10. * @LastEditTime: 2021-05-08 17:30:21
  11. * @LastEditors: your name
  12. * @Description: In User Settings Edit
  13. * @FilePath: \admin_php\modules\client\models\v1\admin\MchSettingForm.php
  14. */
  15. namespace app\modules\client\models\v1\admin;
  16. use app\models\Mch;
  17. use app\models\MchCommonCat;
  18. class MchSettingForm extends \yii\base\Model
  19. {
  20. public $mch_id;
  21. public $model;
  22. public $is_share;
  23. /**
  24. * @return array
  25. */
  26. public function rules()
  27. {
  28. return [
  29. [['mch_id'], 'required'],
  30. [['mch_id', 'is_share'], 'integer'],
  31. [['is_share'], 'default', 'value'=>0]
  32. ];
  33. }
  34. /**
  35. * 保存分类
  36. * @return array
  37. */
  38. public function save()
  39. {
  40. if (!$this->validate()) {
  41. return [
  42. 'code' => 1,
  43. 'msg' => $this->getErrorSummary(false)[0]
  44. ];
  45. }
  46. $this->model->store_id = get_store_id();
  47. $this->model->mch_id = $this->mch_id;
  48. $this->model->attributes = $this->attributes;
  49. if ($this->model->save()) {
  50. return [
  51. 'code' => 0,
  52. 'msg' => '提交成功'
  53. ];
  54. } else {
  55. return [
  56. 'code' => 0,
  57. 'msg' => '保存失败'
  58. ];
  59. }
  60. }
  61. public static function getList()
  62. {
  63. $query = Mch::find()->where([
  64. 'is_delete' => 0,
  65. 'store_id' => get_store_id()
  66. ])->with(['user', 'setting']);
  67. $query->andWhere([
  68. 'review_status' => get_params('review_status',1)
  69. ]);
  70. $query->select(['*'])->orderBy(['sort' => SORT_ASC, 'id' => SORT_DESC]);
  71. $pagination = pagination_make($query);
  72. $pagination['data'] = $pagination['list'];
  73. unset($pagination['list']);
  74. return [
  75. 'code' => 0,
  76. 'msg' => 'success',
  77. 'data' => $pagination,
  78. 'common_cat' => MchCommonCat::find()->where([
  79. 'store_id' => get_store_id(),
  80. 'is_delete' => 0
  81. ])->select(['id', 'name'])->orderBy(['sort' => SORT_ASC, 'id' => SORT_DESC])->all()
  82. ];
  83. }
  84. }