PlatformProfitCashForm.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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\SaasProfitCash;
  9. use app\models\SaasUser;
  10. use app\models\StoreShareMoney;
  11. use app\models\User;
  12. use app\utils\Wechat\WechatNewPay;
  13. use yii\base\Model;
  14. class PlatformProfitCashForm extends Model
  15. {
  16. public $id;
  17. public $reason;
  18. public $search_type;
  19. public $status = -1;
  20. public $dateStart;
  21. public $dateEnd;
  22. public $keyword;
  23. public $name;
  24. public $mobile;
  25. public $type;
  26. public $store_id;
  27. public $is_daili;//是否为代理账户
  28. public function rules()
  29. {
  30. return [
  31. [['store_id', 'search_type', 'status', 'type', 'id', 'is_daili'], 'integer'],
  32. [['keyword', 'dateStart', 'dateEnd', 'name', 'mobile'], 'string', 'max' => 255],
  33. [['keyword'], 'trim'],
  34. ];
  35. }
  36. public function search() {
  37. if (!$this->validate()) {
  38. return [
  39. 'code' => 1,
  40. 'msg' => $this->getErrorSummary(false)[0]
  41. ];
  42. }
  43. $saas_user_id = 0;
  44. if ((int)$this->is_daili === 1) {
  45. $admin = get_admin();
  46. $saas_user_id = $admin->saas_user_id;
  47. $SaasUser = SaasUser::findOne($saas_user_id);
  48. }
  49. $query = SaasProfitCash::find()->alias('spc')
  50. ->leftJoin(['su' => SaasUser::tableName()],'su.id=spc.user_id')->where(['spc.is_delete' => 0]);
  51. if (!empty($saas_user_id)) {
  52. $query->andWhere(['spc.user_id' => $saas_user_id]);
  53. }
  54. // 名称
  55. if ($this->name) {
  56. $query->andWhere(['like', 'su.name', $this->name]);
  57. }
  58. // 手机号
  59. if ($this->mobile) {
  60. $query->andWhere(['like', 'spc.mobile', $this->mobile]);
  61. }
  62. // 提现方式
  63. if ((int)$this->type !== -1 && $this->type !== null && $this->type !== '') {
  64. $query->andWhere(['spc.type' => $this->type]);
  65. }
  66. // 状态
  67. if ((int)$this->status !== -1 && $this->status !== null) {
  68. $query->andWhere(['spc.status' => $this->status]);
  69. }
  70. $query->orderBy('spc.created_at DESC, spc.updated_at DESC')
  71. ->groupBy('spc.order_no')
  72. ->select('spc.*, su.name, su.avatar, su.name');
  73. $list = pagination_make($query);
  74. foreach ($list['list'] as &$val) {
  75. $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
  76. $val['updated_at'] = date('Y-m-d H:i:s', $val['updated_at']);
  77. }
  78. return [
  79. 'code' => 0,
  80. 'msg' => 'success',
  81. 'data' => [
  82. 'data' => $list['list'],
  83. 'pageNo' => $list['pageNo'],
  84. 'totalCount' => $list['totalCount'],
  85. 'share_profit' => $SaasUser->share_profit ?? '0.00'
  86. ]
  87. ];
  88. }
  89. /**
  90. * 联盟佣金提现审核
  91. * @return array
  92. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  93. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  94. * @throws \GuzzleHttp\Exception\GuzzleException
  95. */
  96. public function audit() {
  97. $cash = SaasProfitCash::findOne(['is_delete' => 0, 'id' => $this->id, 'status' => SaasProfitCash::CASH_STATUS_WAIT]);
  98. if (!$cash) {
  99. return [
  100. 'code' => 1,
  101. 'msg' => '记录不存在'
  102. ];
  103. }
  104. // 拒绝
  105. if ($this->status == SaasProfitCash::CASH_STATUS_FAIL) {
  106. $saas_user = SaasUser::findOne($cash->user_id);
  107. $saas_user->share_profit = (($saas_user->share_profit * 1) + ($cash->amount * 1) + ($cash->service_money * 1));
  108. $saas_user->save();
  109. $cash->status = SaasProfitCash::CASH_STATUS_FAIL;
  110. $cash->refuse_reason = !empty($this->reason) ? trim($this->reason) : '';
  111. if (!$cash->save()) {
  112. return [
  113. 'code' => 1,
  114. 'msg' => implode(';', array_values($cash->firstErrors))
  115. ];
  116. }
  117. return [
  118. 'code' => 0,
  119. 'msg' => '操作成功'
  120. ];
  121. }
  122. // 通过
  123. if ($this->status == SaasProfitCash::CASH_STATUS_PASS) {
  124. $cash->status = SaasProfitCash::CASH_STATUS_PASS;
  125. if (!$cash->save()) {
  126. return [
  127. 'code' => 1,
  128. 'msg' => implode(';', array_values($cash->firstErrors))
  129. ];
  130. }
  131. $form = new StoreShareMoney();
  132. $form->user_id = $cash->user_id;
  133. $form->store_id = 0;
  134. $form->profit = 0;
  135. $form->total_price = $cash->amount;
  136. $form->desc = "用户提现";
  137. $form->order_id = $cash->id;
  138. $form->created_at = time();
  139. $form->status = StoreShareMoney::STATUS_STORE_PAYOUTS;
  140. $form->commission = 0;
  141. if (!$form->save()) {
  142. return [
  143. 'code' => 1,
  144. 'msg' => implode(';', array_values($form->firstErrors))
  145. ];
  146. }
  147. return [
  148. 'code' => 0,
  149. 'msg' => '操作成功'
  150. ];
  151. }
  152. return [
  153. 'code' => 1,
  154. 'msg' => '操作异常'
  155. ];
  156. }
  157. public function del()
  158. {
  159. try {
  160. $id = $this->id;
  161. $cash = SaasProfitCash::findOne($id);
  162. if (!$cash) {
  163. throw new \Exception("查找失败");
  164. }
  165. $cash->is_delete = 1;
  166. if (get_saas_user_id()) {
  167. throw new \Exception("身份信息错误");
  168. }
  169. if (!$cash->save()) {
  170. throw new \Exception(json_encode($cash->errors));
  171. }
  172. return [
  173. 'code' => 0,
  174. 'msg' => "操作成功"
  175. ];
  176. } catch (\Exception $e) {
  177. return [
  178. 'code' => 1,
  179. 'msg' => '操作异常' . $e->getMessage()
  180. ];
  181. }
  182. }
  183. }