MchWithdrawLog.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <?php
  2. namespace addons\Mch\common\models;
  3. use addons\Alitopay\common\enums\AlitoapyEnum;
  4. use addons\Alitopay\common\models\Order;
  5. use addons\Alitopay\common\services\AlipayService;
  6. use addons\Alitopay\common\services\SettingService;
  7. use addons\AvoidTax\common\service\UserService;
  8. use addons\JoinPay\common\global_func\withdraw_way\WithdrawWay;
  9. use common\components\export\CsvTool;
  10. use common\enums\DownloadEnum;
  11. use common\enums\PayTypeEnum;
  12. use common\enums\RedisKeyEnum;
  13. use common\enums\StatusEnum;
  14. use common\enums\UserWalletEnum;
  15. use common\helpers\LockHelper;
  16. use common\helpers\StringHelper;
  17. use common\logic\common\PaymentLogic;
  18. use common\models\base\BaseActiveRecord;
  19. use common\models\common\Download;
  20. use common\models\common\PaymentTransfer;
  21. use common\models\user\User;
  22. use common\models\user\UserInfo;
  23. use services\common\PayService;
  24. use services\common\UserWalletService;
  25. use Yii;
  26. use yii\db\Exception;
  27. /**
  28. * This is the model class for table "qimall_addons_mch_withdraw_log".
  29. *
  30. * @property int $id
  31. * @property int $mall_id 商城id
  32. * @property int $mch_id 多商户id
  33. * @property int $user_id 会员id
  34. * @property string $order_no 提现订单号
  35. * @property float $num 提现金额
  36. * @property float $actual_num 实际到账金额
  37. * @property float $poundage_num 手续费扣除金额
  38. * @property float $poundage_ratio 手续费比例
  39. * @property string $type 提现方式 bank--银行转账 balance--打款到余额
  40. * @property string $extra 额外信息
  41. * @property int $withdraw_status 提现状态 0--待打款 --已打款 2--驳回
  42. * @property int $status 状态[0禁用 1启用 -1删除]
  43. * @property string $remark 备注
  44. * @property int|null $created_at 添加时间戳
  45. * @property int|null $updated_at 更新时间戳
  46. */
  47. class MchWithdrawLog extends BaseActiveRecord
  48. {
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public static function tableName()
  53. {
  54. return '{{%addons_mch_withdraw_log}}';
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function rules()
  60. {
  61. return [
  62. [['mall_id', 'mch_id', 'user_id', 'withdraw_status', 'status', 'created_at', 'updated_at'], 'integer'],
  63. [['num', 'actual_num', 'poundage_num', 'poundage_ratio'], 'number'],
  64. [['extra'], 'required'],
  65. [['extra', 'remark'], 'string'],
  66. [['order_no', 'remark'], 'string', 'max' => 255],
  67. [['type'], 'string', 'max' => 45],
  68. ];
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function attributeLabels()
  74. {
  75. return [
  76. 'id' => 'ID',
  77. 'mall_id' => '商城id',
  78. 'mch_id' => '多商户id',
  79. 'user_id' => '会员id',
  80. 'order_no' => '提现订单号',
  81. 'num' => '提现金额',
  82. 'actual_num' => '实际到账金额',
  83. 'poundage_num' => '手续费扣除金额',
  84. 'poundage_ratio' => '手续费比例',
  85. 'type' => '提现方式 bank--银行转账 balance--打款到余额',
  86. 'extra' => '额外信息',
  87. 'withdraw_status' => '提现状态 0--待打款 --已打款 2--驳回 ',
  88. 'status' => '状态[0禁用 1启用 -1删除]',
  89. 'remark' => '备注',
  90. 'created_at' => '添加时间戳',
  91. 'updated_at' => '更新时间戳',
  92. ];
  93. }
  94. public static function withdrawApply($params)
  95. {
  96. // $t = Yii::$app->db->beginTransaction();
  97. // $lock_key = RedisKeyEnum::suffix(RedisKeyEnum::LOCK_MCH_BALANCE_WALLET, $params['mch_id']);
  98. $identification = uniqid();
  99. try {
  100. // if (LockHelper::lock($lock_key, $identification, 100, 100)) {
  101. $store = Mch::getOne([['id' => $params['mch_id']]], false, [], false, 'id,mall_id,user_id,balance');
  102. $cash = new self();
  103. $cash->mall_id = $params['mall_id'];
  104. $cash->user_id = $store['user_id'];
  105. $cash->mch_id = $store['id'];
  106. $cash->num = $params['withdrawal_money'];
  107. $cash->actual_num = $params['withdrawal_money'];
  108. $cash->order_no = StringHelper::generateOrderNo('tx');
  109. $cash->extra = json_encode([]);
  110. $cash->status = 1;
  111. $cash->remark = $params['remark'] ?? '';
  112. $extra = [];
  113. $return_data = [];
  114. $withdraw_status = 0;
  115. switch ($params['withdrawal_type']) {
  116. case 'balance':
  117. //提现到个人余额
  118. $cash->type = 'balance';
  119. $desc = '余额提现' . $cash->num;
  120. $data = [
  121. 'message_id' => 0, 'mall_id' => $store['mall_id'], 'user_id' => $store['user_id'],
  122. 'wallet_type' => 'balance',
  123. 'is_frozen' => false, 'unfrozen' => false, 'money' => abs($cash->actual_num),
  124. 'desc' => $desc, 'source_table' => 'user_wallet', 'source_table_id' => $cash->id,
  125. 'from_type' => UserWalletEnum::WITHDRAWAL,
  126. 'capital_type' => UserWalletEnum::RECHARGE_MCH_BALANCE,
  127. ];
  128. $wallet_service_status = UserWalletService::handle(0, $data);
  129. if (!$wallet_service_status) {
  130. throw new Exception('提现失败' . UserWalletService::getStaticError());
  131. }
  132. $withdraw_status = 1;
  133. break;
  134. case 'bank':
  135. case 'joinpay':
  136. case 'yunfast_pay':
  137. if (empty($params['select_bank'])) throw new Exception('请选择银行卡');
  138. $extra = $params['select_bank'];
  139. break;
  140. case 'alitopay':
  141. case 'alipay_offline':
  142. if (empty($params['name'])) throw new Exception('请输入支付宝真实姓名');
  143. if (empty($params['mobile'])) throw new Exception('支付宝绑定的手机号');
  144. // if (empty($params['id_card'])) throw new Exception('请输入支付宝身份证号码');
  145. // $extra['id_card'] = $params['id_card'];
  146. $extra['name'] = $params['name'];
  147. $extra['mobile'] = $params['mobile'];
  148. break;
  149. case 'alipay_tax':
  150. if (empty($params['name'])) throw new Exception('请输入支付宝真实姓名');
  151. if (empty($params['mobile'])) throw new Exception('支付宝绑定的手机号');
  152. $extra['name'] = $params['name'];
  153. $extra['mobile'] = $params['mobile'];
  154. if (empty($params['id_card'])) throw new Exception('请输入支付宝身份证号码');
  155. $extra['id_card'] = $params['id_card'];
  156. $obj = new UserService(['mall_id' => $params['mall_id']]);
  157. $res = $obj->checkSign($store['user_id']);
  158. $data['is_sign'] = 0;
  159. if ($res != false) {
  160. $data['is_sign'] = 1;
  161. $data = array_merge($res, $data);
  162. }
  163. $return_data['is_sign'] = $data['is_sign'];
  164. if (!$data['is_sign']) {
  165. $res = $obj->goToSing($store['user_id'], $params['mobile'], $params['id_card'], $params['name']);
  166. if (!$res) {
  167. throw new Exception($obj->error);
  168. }
  169. $res['is_sign'] = $data['is_sign'];
  170. return ['code' => 1, 'data' => $res];
  171. }
  172. break;
  173. case 'wechat':
  174. if (empty($params['wechat_qrcode'])) throw new Exception('请上传凭证');
  175. $extra['content'] = $params['content'];
  176. $extra['wechat_qrcode'] = $params['wechat_qrcode'];
  177. break;
  178. case 'auto':
  179. $userInfo = UserInfo::findOne(['user_id' => $store['user_id'], 'mall_id' => $params['mall_id'],
  180. 'status' => StatusEnum::ENABLED, 'platform' => ['wechat', 'mp-wx']]);
  181. if (empty($userInfo)) throw new Exception('该商户不存在微信相关信息,请先到前端用微信公众号或者小程序注册');
  182. break;
  183. default:
  184. throw new Exception('提现方式异常');
  185. // }
  186. }
  187. $cash->extra = json_encode($extra);
  188. $cash->type = $params['withdrawal_type'];
  189. if($cash->type!='balance'){
  190. if ($params['balance_cash_service_fee'] > 0 && $params['balance_cash_service_fee'] < 100) {
  191. //手续费:取小数点2位,截断
  192. $poundage = bcmul($params['balance_cash_service_fee'] / 100, $params['withdrawal_money'], 4);
  193. // 四舍五入,保留2位
  194. $poundage = number_format($poundage, 2, '.', '');
  195. $cash->actual_num = bcsub($params['withdrawal_money'], $poundage, 2);
  196. $cash->poundage_num = $poundage;
  197. $cash->poundage_ratio = $params['balance_cash_service_fee'];
  198. }
  199. }
  200. if (intval(bcmul($cash->actual_num, 100)) < 1) {
  201. throw new Exception('提现金额扣除费用后金额不足');
  202. }
  203. $cash->withdraw_status = $withdraw_status;
  204. $res = $cash->save();
  205. if ($res == false) throw new Exception($cash->getErrorMessage());
  206. $store->balance -= $params['withdrawal_money'];
  207. $res = $store->save();
  208. if ($res == false) throw new Exception($store->getErrorMessage());
  209. // $t->commit();
  210. // LockHelper::uLock($lock_key, $identification);
  211. return ['code' => 1, 'data' => $return_data];
  212. } catch (\Exception $e) {
  213. // $t->rollBack();
  214. // LockHelper::uLock($lock_key, $identification);
  215. self::$static_error = $e->getMessage();
  216. return [];
  217. }
  218. }
  219. /**
  220. * @name:
  221. * @msg: 后台审核门店提现申请
  222. * @param {int} $mall_id
  223. * @param {array} $params
  224. * @return {*}
  225. */
  226. public static function cashAudit(int $mall_id, array $params)
  227. {
  228. $log = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $params['id'], 'withdraw_status' => 0]);
  229. if (empty($log)) {
  230. self::$static_error = '提现记录不存在';
  231. return false;
  232. }
  233. // $transaction = \Yii::$app->db->beginTransaction();
  234. try {
  235. $res = false;
  236. switch ($params['withdraw_status']) {
  237. case 1:
  238. $cash = [
  239. 'actual_num' => $log['actual_num'],
  240. 'mall_id' => $log['mall_id'],
  241. 'user_id' => $log['user_id'],
  242. 'order_no' => $log['order_no'],
  243. ];
  244. switch ($log['type']) {
  245. case "joinpay":
  246. //汇聚代付
  247. $extraArr = json_decode($log['extra'], true);
  248. $extra = json_encode([
  249. 'bank_account' => $extraArr['bank_card_no'],
  250. 'name' => $extraArr['payer_name'],
  251. 'bank_account_type' => $extraArr['bank_account_type'],
  252. ]);
  253. $cash['extra'] = $extra;
  254. $data['cash'] = json_decode(json_encode($cash));
  255. $data['title'] = '商户余额提现';
  256. $data['source'] = '3';
  257. $res = WithdrawWay::extensionWithdrawPay($data);
  258. break;
  259. case "alitopay":
  260. $extraArr = json_decode($log['extra'], true);
  261. $res = self::withdrawToPay($mall_id, $log['id'], $log['order_no'], $extraArr['name'], $extraArr['mobile'], $log['actual_num']);
  262. break;
  263. case "alipay_offline":
  264. case "bank":
  265. case "wechat":
  266. $res = true;
  267. break;
  268. case "auto":
  269. $userInfo = UserInfo::getOne([["user_id" => $log->user_id, "platform" => [User::PLATFORM_WECHAT, User::PLATFORM_MP_WX], "status" => StatusEnum::ENABLED]]);
  270. try {
  271. $cash['extra'] = [];
  272. $payment = new PayService();
  273. $paymentTransfer = new PaymentTransfer();
  274. $paymentTransfer->orderNo = PaymentTransfer::generate_order_no("TX");
  275. $paymentTransfer->user = $userInfo;
  276. $paymentTransfer->title = "收益提现";
  277. $paymentTransfer->amount = $log['actual_num'];
  278. $paymentTransfer->transferType = PayTypeEnum::WECHAT;
  279. $paymentTransfer->withdrawal_source = 'MchWithdrawLog';
  280. $paymentTransfer->withdrawal_source_id = $log['id'];
  281. $paymentTransfer->cashInfo = $cash;
  282. $res = $payment->transfer($paymentTransfer);
  283. } catch (Exception $e) {
  284. throw new \Exception($e->getMessage());
  285. }
  286. break;
  287. case 'alipay_tax':
  288. break;
  289. }
  290. if ($res) {
  291. $log->withdraw_status = $params['withdraw_status'];
  292. $log->remark = $params['remark'];
  293. $log->updated_at = time();
  294. $res = $log->save();
  295. if (!$res) {
  296. throw new \Exception($log->getErrorMessage());
  297. }
  298. }
  299. break;
  300. case 2:
  301. // 驳回提现申请,退回已经扣除的余额
  302. $lock_key = RedisKeyEnum::suffix(RedisKeyEnum::LOCK_MCH_BALANCE_WALLET, $log->mch_id);
  303. $identification = uniqid();
  304. if (LockHelper::lock($lock_key, $identification, 100, 100)) {
  305. // 退回的金额
  306. $store = Mch::findOne(['mall_id' => $mall_id, 'id' => $log->mch_id, 'user_id' => $log->user_id]);
  307. $store->balance = bcadd($store->balance, $log->num, 2);
  308. $res_store = $store->save();
  309. $log->withdraw_status = $params['withdraw_status'];
  310. $log->remark = $params['remark'];
  311. $log->updated_at = time();
  312. $res = $log->save();
  313. if (!$res_store) {
  314. throw new \Exception($store->getErrorMessage());
  315. }
  316. LockHelper::uLock($lock_key, $identification);
  317. $res = true;
  318. } else {
  319. throw new \Exception('系统繁忙,请稍后再试');
  320. }
  321. break;
  322. }
  323. // $transaction->commit();
  324. return $res;
  325. } catch (\Exception $e) {
  326. self::$static_error = $e->getMessage();
  327. // $transaction->rollBack();
  328. return false;
  329. }
  330. }
  331. public static function withdrawToPay($mall_id, $source_id, $order_no, $name, $mobile, $money)
  332. {
  333. // 获取设置
  334. $setting = (new SettingService($mall_id))->getSetting();
  335. if (empty($setting)) throw new \Exception('未进行代付配置');
  336. // 加锁
  337. $uniqid = uniqid();
  338. $lock_key = 'alitopay_order_lock_' . $mall_id;
  339. if (!LockHelper::lock($lock_key, $uniqid)) throw new \Exception('操作频繁请稍后重试');
  340. // 拼接数据入表
  341. $insert_data = [];
  342. $time = time();
  343. // 是否达到最低打款金额
  344. if ($money < AlitoapyEnum::MIX_WITHDRAW) {
  345. throw new \Exception("订单{$name},打款金额必须大于1元");
  346. }
  347. // 数据
  348. $data['mall_id'] = $mall_id;
  349. $data['order_sn'] = $time . rand(1000, 9999);
  350. $data['type'] = Order::TYPE_WITHDRAWAL;
  351. $data['money'] = $money;
  352. $data['name'] = $name;
  353. $data['account'] = $mobile;
  354. $data['source_id'] = $source_id;
  355. $data['source_sn'] = $order_no;
  356. $data['created_at'] = $data['updated_at'] = $time;
  357. $insert_data[] = $data;
  358. // 开启事务
  359. $db = Yii::$app->db->beginTransaction();
  360. try {
  361. // 批量插入
  362. Order::batchInsert($insert_data);
  363. // 批量修改打款中
  364. $db->commit();
  365. } catch (\Exception $e) {
  366. $db->rollBack();
  367. LockHelper::uLock($lock_key, $uniqid);
  368. throw new \Exception($e->getMessage());
  369. }
  370. // 批量进行打款
  371. $count = self::aliPay($mall_id, $insert_data);
  372. LockHelper::uLock($lock_key, $uniqid);
  373. return $count;
  374. }
  375. private static function aliPay($mall_id, array $list)
  376. {
  377. $aliapy = new AlipayService($mall_id);
  378. // 创建一个批次号
  379. $out_batch_no = 'TX' . date('Ymd') . $mall_id . rand(1000, 9999);
  380. $count = 0;
  381. $sub_msg = null;
  382. foreach ($list as $v) {
  383. // 打款
  384. $res = $aliapy->transfer(
  385. $v['money'], $v['name'], $v['account'], $v['order_sn']
  386. );
  387. if ($res['code'] == '10000') {
  388. // 打款成功
  389. Order::paySuccessBySourceIdAndOrderSn(
  390. $v['source_id'], $v['order_sn'],$res['order_id']
  391. );
  392. $count++;
  393. } else {
  394. // 打款失败
  395. Order::payFialBySourceIdAndOrderSn(
  396. $v['source_id'], $v['order_sn'], $res['sub_msg']
  397. );
  398. $sub_msg = $res['sub_msg'];
  399. }
  400. }
  401. // 设置批次号
  402. Order::setOutBatchNoByOrderSn($out_batch_no, array_column($list, 'order_sn'));
  403. if (isset($sub_msg)) {
  404. throw new \Exception($sub_msg);
  405. }
  406. return $count;
  407. }
  408. /**
  409. * @name:
  410. * @msg: 导出字段列表
  411. * @param {array} $fields
  412. * @return {*}
  413. */
  414. public static function exportFieldList(array $fields = null)
  415. {
  416. $field_list = [
  417. 'nickname' => '会员昵称',
  418. 'mobile' => '手机号',
  419. 'type' => '提现方式',
  420. 'account_username' => '收款账户名',
  421. 'account_no' => '收款账户',
  422. 'account_organization' => '收款机构',
  423. 'num' => '提现金额',
  424. 'poundage_num' => '手续费',
  425. 'actual_num' => '实际打款金额',
  426. 'remark' => '备注',
  427. 'created_at' => '付款时间',
  428. ];
  429. if (empty($fields)) {
  430. return $field_list;
  431. } else {
  432. $new_list = [];
  433. foreach ($fields as $val) {
  434. if (!empty($field_list[$val])) {
  435. $new_list[$val] = $fields[$val];
  436. }
  437. }
  438. return $new_list;
  439. }
  440. }
  441. public static function exportHandle(array $data = null)
  442. {
  443. try {
  444. $download_id = $data['download_id'] ?? 0;
  445. $download = Download::findOne(['id' => $download_id]);
  446. $params = json_decode($download->params, true);
  447. // dd($params);
  448. $have_select_field_arr = [];
  449. $all_fields = self::exportFieldList();
  450. $fields = $params['fields'] ?? [];
  451. if (!empty($fields)) {
  452. foreach ($fields as $field) {
  453. $have_select_field_arr[] = $all_fields[$field];
  454. }
  455. } else {
  456. $have_select_field_arr = $all_fields;
  457. }
  458. // dd($have_select_field_arr);
  459. $csv = new CsvTool();
  460. $csv->filename = $download->name;
  461. $csv->file_dirname = DownloadEnum::getTypeStorageDirMap($download->type);
  462. $csv->export_mode = CsvTool::EXPORT_MODE_ASYNC;
  463. $csv->header = $have_select_field_arr;
  464. $cash_status_map = ['waiting-payment' => 0, 'payment' => 1, 'refund' => 2];
  465. $list_query = self::find()->where(['mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED, 'withdraw_status' => $cash_status_map[$params['curr_tabname']]]);
  466. if (!empty($params['user_id'])) {
  467. $wheres[] = ['user_id' => $params['user_id']];
  468. }
  469. if (!empty($params['nickname'])) {
  470. $users = User::find()
  471. ->select('id,nickname,mobile,avatar_url')
  472. ->where(['mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED])
  473. ->andWhere(['like', 'nickname', $params['nickname']])
  474. ->asArray()
  475. ->indexBy('id')
  476. ->all();
  477. $wheres[] = ['user_id' => array_column($users, 'id')];
  478. }
  479. if (!empty($params['start_time'])) {
  480. $wheres[] = ['>=', 'created_at', strtotime($params['start_time'])];
  481. }
  482. if (!empty($params['end_time'])) {
  483. $wheres[] = ['<=', 'created_at', strtotime($params['end_time'] . ' 23:59:59')];
  484. }
  485. $rows = [];
  486. $type_map= PaymentLogic::getWithdrawTypeMap($params['mall_id']);
  487. foreach ($list_query->asArray()->batch(200) as $lists) {
  488. if (empty($users)) {
  489. $user_ids = array_column($lists, 'user_id');
  490. $users = User::find()
  491. ->select('id,nickname,mobile,avatar_url')
  492. ->where(['mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
  493. ->asArray()
  494. ->indexBy('id')
  495. ->all();
  496. }
  497. foreach ($lists as &$list) {
  498. $user = $users[$list['user_id']] ?? '';
  499. $list['nickname'] = $user['nickname'] ?? '';
  500. $list['mobile'] = $user['mobile'] ?? '';
  501. $list['account_no'] = $list['account_username'] = $list['account_organization'] = '';
  502. switch ($list['type']) {
  503. case 'bank':
  504. case 'joinpay':
  505. $extra = json_decode($list['extra'], true);
  506. $list['account_no'] = $extra['bank_card_no'] ?? '';
  507. $list['account_username'] = $extra['payer_name'] ?? '';
  508. $list['account_organization'] = $extra['bank_name'] ?? '';
  509. break;
  510. case 'alipay':
  511. $extra = json_decode($list['extra'], true);
  512. $list['account_no'] = $extra['mobile'] ?? '';
  513. $list['account_username'] = $extra['name'] ?? '';
  514. $list['account_organization'] = '';
  515. break;
  516. case 'balance':
  517. $list['account_no'] = $user['mobile'] ?? '';
  518. $list['account_username'] = $user['nickname'] ?? '';
  519. $list['account_organization'] = '平台';
  520. break;
  521. case 'auto':
  522. $list['account_no'] = $user['mobile'] ?? '';
  523. $list['account_username'] = $user['nickname'] ?? '';
  524. $list['account_organization'] = '';
  525. break;
  526. }
  527. $arr = [];
  528. foreach ($fields as $field) {
  529. if (!empty($list[$field])) {
  530. if ('created_at' == $field) {
  531. $list[$field] = date('Y-m-d H:i:s', $list[$field]);
  532. }
  533. if ('mobile' == $field) {
  534. $list[$field] = (string)$list[$field];
  535. }
  536. if($field=='type'){
  537. $list[$field] = $type_map[$list[$field]]??'';
  538. }
  539. } else {
  540. $list[$field] = '';
  541. }
  542. $arr[] = $list[$field];
  543. }
  544. $rows[] = $arr;
  545. }
  546. }
  547. $csv->data = $rows;
  548. $csv->export();
  549. $csv->updateDown($download, $params['mall_id']);
  550. return true;
  551. } catch (\Exception $e) {
  552. $download->status = 3;
  553. $res = $download->save();
  554. self::setStaticError($e->getMessage());
  555. return $e->getMessage();
  556. }
  557. }
  558. /**
  559. * 打款失败,变成待打款状态,让客户自己去驳回
  560. * @param $withdraw_log
  561. * @param $msg
  562. */
  563. public static function remit_fail($withdraw_log, $msg)
  564. {
  565. $res = MchWithdrawLog::updateAll([
  566. 'withdraw_status' => 0,
  567. 'remark' => '打款结果:' . $msg,
  568. 'updated_at' => time()
  569. ], ['id' => $withdraw_log->id]);
  570. }
  571. }