Predeposit.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Predeposit extends BaseModel
  12. {
  13. public $page_info;
  14. public $rcblog_type_text = array(
  15. 'order_pay' => '下单使用',
  16. 'order_freeze' => '下单冻结',
  17. 'order_cancel' => '取消订单解冻',
  18. 'order_comb_pay' => '下单扣除被冻结',
  19. 'recharge' => '平台充值卡充值',
  20. 'refund' => '确认退款',
  21. 'vr_refund' => '虚拟兑码退款',
  22. 'bonus' => '红包奖励',
  23. );
  24. public $lg_type_text = array(
  25. 'order_pay' => '下单使用',
  26. 'order_freeze' => '下单冻结',
  27. 'order_cancel' => '取消订单解冻',
  28. 'order_comb_pay' => '下单扣除被冻结',
  29. 'recharge' => '平台充值卡充值',
  30. 'cash_apply' => '申请提现冻结预存款',
  31. 'cash_pay' => '提现成功',
  32. 'cash_del' => '取消提现申请',
  33. 'refund' => '确认退款',
  34. 'vr_refund' => '虚拟兑码退款',
  35. );
  36. /**
  37. * 增加充值卡
  38. * @access public
  39. * @author csdeshang
  40. * @param type $sn
  41. * @param type $member_info
  42. * @return type
  43. * @throws \app\common\model\Exception
  44. */
  45. public function addRechargecard($sn, $member_info)
  46. {
  47. $member_id = $member_info['member_id'];
  48. $member_name = $member_info['member_name'];
  49. if ($member_id < 1 || !$member_name) {
  50. return array('message' => '当前登录状态为未登录,不能使用充值卡');
  51. }
  52. $rechargecard_model = model('rechargecard');
  53. $card = $rechargecard_model->getRechargecardBySN($sn);
  54. if (empty($card) || $card['rc_state'] != 0 || $card['member_id'] != 0) {
  55. return array('message' => '充值卡不存在或已被使用');
  56. }
  57. $card['member_id'] = $member_id;
  58. $card['member_name'] = $member_name;
  59. try {
  60. Db::startTrans();
  61. $rechargecard_model->setRechargecardUsedById($card['rc_id'], $member_id, $member_name);
  62. $card['amount'] = $card['rc_denomination'];
  63. $this->changeRcb('recharge', $card);
  64. Db::commit();
  65. } catch (Exception $e) {
  66. Db::rollback();
  67. throw $e;
  68. }
  69. }
  70. /**
  71. * 取得充值列表
  72. * @access public
  73. * @author csdeshang
  74. * @param type $condition 条件
  75. * @param type $pagesize 页面大小
  76. * @param type $fields 字段
  77. * @param type $order 排序
  78. * @return type
  79. */
  80. public function getPdRechargeList($condition = array(), $pagesize = '', $fields = '*', $order = '')
  81. {
  82. if ($pagesize) {
  83. $result = Db::name('pdrecharge')->where($condition)->field($fields)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  84. $this->page_info = $result;
  85. return $result->items();
  86. } else {
  87. return Db::name('pdrecharge')->where($condition)->field($fields)->order($order)->select()->toArray();
  88. }
  89. }
  90. /**
  91. * 添加充值记录
  92. * @access public
  93. * @author csdeshang
  94. * @param type $data 参数内容
  95. * @return bool
  96. */
  97. public function addPdRecharge($data)
  98. {
  99. return Db::name('pdrecharge')->insertGetId($data);
  100. }
  101. /**
  102. * 编辑
  103. * @access public
  104. * @author csdeshang
  105. * @param type $data 数据
  106. * @param type $condition 条件
  107. * @return bool
  108. */
  109. public function editPdRecharge($data, $condition = array())
  110. {
  111. return Db::name('pdrecharge')->where($condition)->update($data);
  112. }
  113. /**
  114. * 取得单条充值信息
  115. * @access public
  116. * @author csdeshang
  117. * @param type $condition 条件
  118. * @param type $fields 字段
  119. * @return type
  120. */
  121. public function getPdRechargeInfo($condition = array(), $fields = '*')
  122. {
  123. return Db::name('pdrecharge')->where($condition)->field($fields)->find();
  124. }
  125. /**
  126. * 取充值信息总数
  127. * @access public
  128. * @author csdeshang
  129. * @param array $condition 条件
  130. * @return int
  131. */
  132. public function getPdRechargeCount($condition = array())
  133. {
  134. return Db::name('pdrecharge')->where($condition)->count();
  135. }
  136. /**
  137. * 取提现单信息总数
  138. * @access public
  139. * @author csdeshang
  140. * @param type $condition 条件
  141. * @return int
  142. */
  143. public function getPdcashCount($condition = array())
  144. {
  145. return Db::name('pdcash')->where($condition)->count();
  146. }
  147. /**
  148. * 取日志总数
  149. * @access public
  150. * @author csdeshang
  151. * @param type $condition 条件
  152. * @return int
  153. */
  154. public function getPdLogCount($condition = array())
  155. {
  156. return Db::name('pdlog')->where($condition)->count();
  157. }
  158. /**
  159. * 取得预存款变更日志列表
  160. * @access public
  161. * @author csdeshang
  162. * @param type $condition 条件
  163. * @param type $pagesize 页面信息
  164. * @param type $fields 字段
  165. * @param type $order 排序
  166. * @param type $limit 限制
  167. * @return array
  168. */
  169. public function getPdLogList($condition = array(), $pagesize = '', $fields = '*', $order = '', $limit = 0)
  170. {
  171. if ($pagesize) {
  172. $pdlog_list_paginate = Db::name('pdlog')->where($condition)->field($fields)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  173. $this->page_info = $pdlog_list_paginate;
  174. return $pdlog_list_paginate->items();
  175. } else {
  176. $pdlog_list_paginate = Db::name('pdlog')->where($condition)->field($fields)->order($order)->limit($limit)->select()->toArray();
  177. return $pdlog_list_paginate;
  178. }
  179. }
  180. /**
  181. * 变更充值卡余额
  182. * @access public
  183. * @author csdeshang
  184. * @param type $type 类型
  185. * @param type $data 数据
  186. * @return type
  187. */
  188. public function changeRcb($type, $data = array())
  189. {
  190. $amount = (float) $data['amount'];
  191. if ($amount < .01) {
  192. throw new \think\Exception('参数错误', 10006);
  193. }
  194. $available = $freeze = 0;
  195. $desc = null;
  196. switch ($type) {
  197. case 'order_pay':
  198. $available = -$amount;
  199. $desc = '下单,使用充值卡余额,订单号: ' . $data['order_sn'];
  200. break;
  201. case 'order_freeze':
  202. $available = -$amount;
  203. $freeze = $amount;
  204. $desc = '下单,冻结充值卡余额,订单号: ' . $data['order_sn'];
  205. break;
  206. case 'order_cancel':
  207. $available = $amount;
  208. $freeze = -$amount;
  209. $desc = '取消订单,解冻充值卡余额,订单号: ' . $data['order_sn'];
  210. break;
  211. case 'order_comb_pay':
  212. $freeze = -$amount;
  213. $desc = '下单,扣除被冻结的充值卡余额,订单号: ' . $data['order_sn'];
  214. break;
  215. case 'storejoinin_pay':
  216. $available = -$amount;
  217. $desc = '店铺入驻,使用充值卡余额,订单号: ' . $data['order_sn'];
  218. break;
  219. case 'storejoinin_freeze':
  220. $available = -$amount;
  221. $freeze = $amount;
  222. $desc = '店铺入驻,冻结充值卡余额,订单号: ' . $data['order_sn'];
  223. break;
  224. case 'storejoinin_cancel':
  225. $available = $amount;
  226. $freeze = -$amount;
  227. $desc = '取消店铺入驻,解冻充值卡余额,订单号: ' . $data['order_sn'];
  228. break;
  229. case 'storejoinin_comb_pay':
  230. $freeze = -$amount;
  231. $desc = '店铺入驻,扣除被冻结的充值卡余额,订单号: ' . $data['order_sn'];
  232. break;
  233. case 'recharge':
  234. $available = $amount;
  235. $desc = '平台充值卡充值,充值卡号: ' . $data['rc_sn'];
  236. break;
  237. case 'refund':
  238. $available = $amount;
  239. $desc = '确认退款,订单号: ' . $data['order_sn'];
  240. break;
  241. case 'vr_refund':
  242. $available = $amount;
  243. $desc = '虚拟兑码退款成功,订单号: ' . $data['order_sn'];
  244. break;
  245. case 'bonus':
  246. $available = $amount;
  247. $desc = $data['rcblog_description'];
  248. break;
  249. default:
  250. throw new \think\Exception('参数错误', 10006);
  251. }
  252. $update = array();
  253. if ($available) {
  254. $update['available_rc_balance'] = Db::raw('available_rc_balance+' . $available);
  255. }
  256. if ($freeze) {
  257. $update['freeze_rc_balance'] = Db::raw('freeze_rc_balance+' . $freeze);
  258. }
  259. if (!$update) {
  260. throw new \think\Exception('参数错误', 10006);
  261. }
  262. // 更新会员
  263. $updateSuccess = model('member')->editMember(array(
  264. 'member_id' => $data['member_id'],
  265. ), $update, $data['member_id']);
  266. if (!$updateSuccess) {
  267. throw new \think\Exception('操作失败', 10006);
  268. }
  269. // 添加日志
  270. $rcblog = array(
  271. 'member_id' => $data['member_id'],
  272. 'member_name' => $data['member_name'],
  273. 'rcblog_type' => $type,
  274. 'rcblog_addtime' => TIMESTAMP,
  275. 'available_amount' => $available,
  276. 'freeze_amount' => $freeze,
  277. 'rcblog_description' => $desc,
  278. );
  279. $insertSuccess = Db::name('rcblog')->insertGetId($rcblog);
  280. if (!$insertSuccess) {
  281. throw new \think\Exception('操作失败', 10006);
  282. }
  283. $msg = array(
  284. 'code' => 'recharge_card_balance_change',
  285. 'member_id' => $data['member_id'],
  286. 'param' => array(
  287. 'time' => date('Y-m-d H:i:s', TIMESTAMP),
  288. 'url' => HOME_SITE_URL . '/Predeposit/rcb_log_list',
  289. 'available_amount' => ds_price_format($available),
  290. 'freeze_amount' => ds_price_format($freeze),
  291. 'description' => $desc,
  292. ),
  293. 'ali_param' => array(
  294. 'time' => date('Y-m-d H:i:s', TIMESTAMP),
  295. 'available_amount' => ds_price_format($available),
  296. 'freeze_amount' => ds_price_format($freeze),
  297. 'description' => $desc,
  298. ),
  299. 'ten_param' => array(
  300. date('Y-m-d H:i:s', TIMESTAMP),
  301. $desc,
  302. ds_price_format($available),
  303. ds_price_format($freeze),
  304. ),
  305. 'weixin_param' => array(
  306. 'url' => config('ds_config.h5_site_url') . '/pages/member/predeposit/RechargeCardList',
  307. 'data' => array(
  308. "keyword1" => array(
  309. "value" => isset($this->rcblog_type_text[$type]) ? $this->rcblog_type_text[$type] : $type,
  310. "color" => "#333"
  311. ),
  312. "keyword2" => array(
  313. "value" => $amount,
  314. "color" => "#333"
  315. ),
  316. "keyword3" => array(
  317. "value" => date('Y-m-d H:i'),
  318. "color" => "#333"
  319. ),
  320. "keyword4" => array(
  321. "value" => $available,
  322. "color" => "#333"
  323. )
  324. ),
  325. )
  326. );
  327. // 发送买家消息
  328. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendMemberMsg', 'cron_value' => serialize($msg)));
  329. return $insertSuccess;
  330. }
  331. /**
  332. * 变更预存款
  333. * @access public
  334. * @author csdeshang
  335. * @param type $change_type
  336. * @param type $data
  337. * @return type
  338. */
  339. public function changePd($change_type, $data = array())
  340. {
  341. $data_log = array();
  342. $data_pd = array();
  343. $data_msg = array();
  344. $data_log['lg_member_id'] = $data['member_id'];
  345. $data_log['lg_member_name'] = $data['member_name'];
  346. $data_log['lg_addtime'] = TIMESTAMP;
  347. $data_log['lg_type'] = $change_type;
  348. $data_msg['time'] = date('Y-m-d H:i:s');
  349. switch ($change_type) {
  350. case 'order_pay':
  351. $data_log['lg_av_amount'] = -$data['amount'];
  352. $data_log['lg_desc'] = '下单,支付预存款,订单号: ' . $data['order_sn'];
  353. $data_pd['available_predeposit'] = Db::raw('available_predeposit-' . $data['amount']);
  354. $data_msg['av_amount'] = -$data['amount'];
  355. $data_msg['freeze_amount'] = 0;
  356. $data_msg['desc'] = $data_log['lg_desc'];
  357. break;
  358. case 'store_rechargew_pay':
  359. $data_log['lg_av_amount'] = -$data['amount'];
  360. $data_log['lg_desc'] = '充值店铺资金,订单号: ' . $data['order_sn'];
  361. $data_pd['available_predeposit'] = Db::raw('available_predeposit-' . $data['amount']);
  362. $data_msg['av_amount'] = -$data['amount'];
  363. $data_msg['freeze_amount'] = 0;
  364. $data_msg['desc'] = $data_log['lg_desc'];
  365. break;
  366. case 'store_withdraw':
  367. $data_log['lg_av_amount'] = $data['amount'];
  368. $data_log['lg_desc'] = '店铺资金提现,订单号: ' . $data['order_sn'];
  369. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  370. $data_msg['av_amount'] = $data['amount'];
  371. $data_msg['freeze_amount'] = 0;
  372. $data_msg['desc'] = $data_log['lg_desc'];
  373. break;
  374. case 'order_freeze':
  375. $data_log['lg_av_amount'] = -$data['amount'];
  376. $data_log['lg_freeze_amount'] = $data['amount'];
  377. $data_log['lg_desc'] = '下单,冻结预存款,订单号: ' . $data['order_sn'];
  378. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit+' . $data['amount']);
  379. $data_pd['available_predeposit'] = Db::raw('available_predeposit-' . $data['amount']);
  380. $data_msg['av_amount'] = -$data['amount'];
  381. $data_msg['freeze_amount'] = $data['amount'];
  382. $data_msg['desc'] = $data_log['lg_desc'];
  383. break;
  384. case 'order_cancel':
  385. $data_log['lg_av_amount'] = $data['amount'];
  386. $data_log['lg_freeze_amount'] = -$data['amount'];
  387. $data_log['lg_desc'] = '取消订单,解冻预存款,订单号: ' . $data['order_sn'];
  388. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit-' . $data['amount']);
  389. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  390. $data_msg['av_amount'] = $data['amount'];
  391. $data_msg['freeze_amount'] = -$data['amount'];
  392. $data_msg['desc'] = $data_log['lg_desc'];
  393. break;
  394. case 'order_comb_pay':
  395. $data_log['lg_freeze_amount'] = -$data['amount'];
  396. $data_log['lg_desc'] = '下单,支付被冻结的预存款,订单号: ' . $data['order_sn'];
  397. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit-' . $data['amount']);
  398. $data_msg['av_amount'] = 0;
  399. $data_msg['freeze_amount'] = -$data['amount'];
  400. $data_msg['desc'] = $data_log['lg_desc'];
  401. break;
  402. case 'storejoinin_pay':
  403. $data_log['lg_av_amount'] = -$data['amount'];
  404. $data_log['lg_desc'] = '店铺入驻,支付预存款,订单号: ' . $data['order_sn'];
  405. $data_pd['available_predeposit'] = Db::raw('available_predeposit-' . $data['amount']);
  406. $data_msg['av_amount'] = -$data['amount'];
  407. $data_msg['freeze_amount'] = 0;
  408. $data_msg['desc'] = $data_log['lg_desc'];
  409. break;
  410. case 'storejoinin_freeze':
  411. $data_log['lg_av_amount'] = -$data['amount'];
  412. $data_log['lg_freeze_amount'] = $data['amount'];
  413. $data_log['lg_desc'] = '店铺入驻,冻结预存款,订单号: ' . $data['order_sn'];
  414. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit+' . $data['amount']);
  415. $data_pd['available_predeposit'] = Db::raw('available_predeposit-' . $data['amount']);
  416. $data_msg['av_amount'] = -$data['amount'];
  417. $data_msg['freeze_amount'] = $data['amount'];
  418. $data_msg['desc'] = $data_log['lg_desc'];
  419. break;
  420. case 'storejoinin_cancel':
  421. $data_log['lg_av_amount'] = $data['amount'];
  422. $data_log['lg_freeze_amount'] = -$data['amount'];
  423. $data_log['lg_desc'] = '取消店铺入驻,解冻预存款,订单号: ' . $data['order_sn'];
  424. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit-' . $data['amount']);
  425. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  426. $data_msg['av_amount'] = $data['amount'];
  427. $data_msg['freeze_amount'] = -$data['amount'];
  428. $data_msg['desc'] = $data_log['lg_desc'];
  429. break;
  430. case 'storejoinin_comb_pay':
  431. $data_log['lg_freeze_amount'] = -$data['amount'];
  432. $data_log['lg_desc'] = '店铺入驻,支付被冻结的预存款,订单号: ' . $data['order_sn'];
  433. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit-' . $data['amount']);
  434. $data_msg['av_amount'] = 0;
  435. $data_msg['freeze_amount'] = -$data['amount'];
  436. $data_msg['desc'] = $data_log['lg_desc'];
  437. break;
  438. case 'recharge':
  439. $data_log['lg_av_amount'] = $data['amount'];
  440. $data_log['lg_desc'] = '充值,充值单号: ' . $data['pdr_sn'];
  441. $data_log['lg_admin_name'] = isset($data['admin_name']) ? $data['admin_name'] : '会员' . $data['member_name'] . '在线充值';
  442. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  443. $data_msg['av_amount'] = $data['amount'];
  444. $data_msg['freeze_amount'] = 0;
  445. $data_msg['desc'] = $data_log['lg_desc'];
  446. break;
  447. case 'refund':
  448. $data_log['lg_av_amount'] = $data['amount'];
  449. $data_log['lg_desc'] = '确认退款,订单号: ' . $data['order_sn'];
  450. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  451. $data_msg['av_amount'] = $data['amount'];
  452. $data_msg['freeze_amount'] = 0;
  453. $data_msg['desc'] = $data_log['lg_desc'];
  454. break;
  455. case 'vr_refund':
  456. $data_log['lg_av_amount'] = $data['amount'];
  457. $data_log['lg_desc'] = '虚拟兑码退款成功,订单号: ' . $data['order_sn'];
  458. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  459. $data_msg['av_amount'] = $data['amount'];
  460. $data_msg['freeze_amount'] = 0;
  461. $data_msg['desc'] = $data_log['lg_desc'];
  462. break;
  463. case 'cash_apply':
  464. $data_log['lg_av_amount'] = -$data['amount'];
  465. $data_log['lg_freeze_amount'] = $data['amount'];
  466. $data_log['lg_desc'] = '申请提现,冻结预存款,提现单号: ' . $data['order_sn'];
  467. $data_pd['available_predeposit'] = Db::raw('available_predeposit-' . $data['amount']);
  468. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit+' . $data['amount']);
  469. $data_msg['av_amount'] = -$data['amount'];
  470. $data_msg['freeze_amount'] = $data['amount'];
  471. $data_msg['desc'] = $data_log['lg_desc'];
  472. break;
  473. case 'cash_pay':
  474. $data_log['lg_freeze_amount'] = -$data['amount'];
  475. $data_log['lg_desc'] = '提现成功,提现单号: ' . $data['order_sn'];
  476. $data_log['lg_admin_name'] = $data['admin_name'];
  477. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit-' . $data['amount']);
  478. $data_msg['av_amount'] = 0;
  479. $data_msg['freeze_amount'] = -$data['amount'];
  480. $data_msg['desc'] = $data_log['lg_desc'];
  481. break;
  482. case 'cash_del':
  483. $data_log['lg_av_amount'] = $data['amount'];
  484. $data_log['lg_freeze_amount'] = -$data['amount'];
  485. $data_log['lg_desc'] = '取消提现申请,解冻预存款,提现单号: ' . $data['order_sn'];
  486. $data_log['lg_admin_name'] = $data['admin_name'];
  487. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  488. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit-' . $data['amount']);
  489. $data_msg['av_amount'] = $data['amount'];
  490. $data_msg['freeze_amount'] = -$data['amount'];
  491. $data_msg['desc'] = $data_log['lg_desc'];
  492. break;
  493. case 'sys_add_money':
  494. $data_log['lg_av_amount'] = $data['amount'];
  495. $data_log['lg_desc'] = '管理员调节预存款【增加】,充值单号: ' . $data['pdr_sn'] . ',备注:' . $data['lg_desc'];
  496. $data_log['lg_admin_name'] = $data['admin_name'];
  497. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  498. $data_msg['av_amount'] = $data['amount'];
  499. $data_msg['freeze_amount'] = 0;
  500. $data_msg['desc'] = $data_log['lg_desc'];
  501. break;
  502. case 'sys_del_money':
  503. $data_log['lg_av_amount'] = -$data['amount'];
  504. $data_log['lg_desc'] = '管理员调节预存款【减少】,充值单号: ' . $data['pdr_sn'] . ',备注:' . $data['lg_desc'];
  505. $data_log['lg_admin_name'] = $data['admin_name'];
  506. $data_pd['available_predeposit'] = Db::raw('available_predeposit-' . $data['amount']);
  507. $data_msg['av_amount'] = -$data['amount'];
  508. $data_msg['freeze_amount'] = 0;
  509. $data_msg['desc'] = $data_log['lg_desc'];
  510. break;
  511. case 'sys_freeze_money':
  512. $data_log['lg_av_amount'] = -$data['amount'];
  513. $data_log['lg_freeze_amount'] = $data['amount'];
  514. $data_log['lg_desc'] = '管理员调节预存款【冻结】,充值单号: ' . $data['pdr_sn'] . ',备注:' . $data['lg_desc'];
  515. $data_log['lg_admin_name'] = $data['admin_name'];
  516. $data_pd['available_predeposit'] = Db::raw('available_predeposit-' . $data['amount']);
  517. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit+' . $data['amount']);
  518. $data_msg['av_amount'] = -$data['amount'];
  519. $data_msg['freeze_amount'] = $data['amount'];
  520. $data_msg['desc'] = $data_log['lg_desc'];
  521. break;
  522. case 'sys_unfreeze_money':
  523. $data_log['lg_av_amount'] = $data['amount'];
  524. $data_log['lg_freeze_amount'] = -$data['amount'];
  525. $data_log['lg_desc'] = '管理员调节预存款【解冻】,充值单号: ' . $data['pdr_sn'] . ',备注:' . $data['lg_desc'];
  526. $data_log['lg_admin_name'] = $data['admin_name'];
  527. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  528. $data_pd['freeze_predeposit'] = Db::raw('freeze_predeposit-' . $data['amount']);
  529. $data_msg['av_amount'] = $data['amount'];
  530. $data_msg['freeze_amount'] = -$data['amount'];
  531. $data_msg['desc'] = $data_log['lg_desc'];
  532. break;
  533. case 'order_inviter':
  534. $data_log['lg_av_amount'] = $data['amount'];
  535. $data_log['lg_desc'] = $data['lg_desc'];
  536. $data_pd['available_predeposit'] = Db::raw('available_predeposit+' . $data['amount']);
  537. $data_msg['av_amount'] = $data['amount'];
  538. $data_msg['freeze_amount'] = 0;
  539. $data_msg['desc'] = $data_log['lg_desc'];
  540. break;
  541. //end
  542. default:
  543. throw new \think\Exception('参数错误', 10006);
  544. break;
  545. }
  546. $update = model('member')->editMember(array('member_id' => $data['member_id']), $data_pd, $data['member_id']);
  547. if (!$update) {
  548. throw new \think\Exception('操作失败', 10006);
  549. }
  550. $insert = Db::name('pdlog')->insertGetId($data_log);
  551. if (!$insert) {
  552. throw new \think\Exception('操作失败', 10006);
  553. }
  554. // 支付成功发送买家消息
  555. $message = array();
  556. $message['code'] = 'predeposit_change';
  557. $message['member_id'] = $data['member_id'];
  558. $data_msg['av_amount'] = ds_price_format($data_msg['av_amount']);
  559. $data_msg['freeze_amount'] = ds_price_format($data_msg['freeze_amount']);
  560. $message['ali_param'] = $data_msg;
  561. $message['ten_param'] = array($data_msg['time'], $data_msg['desc'], $data_msg['av_amount'], $data_msg['freeze_amount']);
  562. $data_msg['pd_url'] = HOME_SITE_URL . '/Predeposit/pd_log_list';
  563. $message['param'] = $data_msg;
  564. $message['weixin_param'] = array(
  565. 'url' => config('ds_config.h5_site_url') . '/pages/member/predeposit/PredepositList',
  566. 'data' => array(
  567. "keyword1" => array(
  568. "value" => isset($this->lg_type_text[$change_type]) ? $this->lg_type_text[$change_type] : $change_type,
  569. "color" => "#333"
  570. ),
  571. "keyword2" => array(
  572. "value" => $data['amount'],
  573. "color" => "#333"
  574. ),
  575. "keyword3" => array(
  576. "value" => date('Y-m-d H:i'),
  577. "color" => "#333"
  578. ),
  579. "keyword4" => array(
  580. "value" => $data_msg['av_amount'],
  581. "color" => "#333"
  582. )
  583. ),
  584. );
  585. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendMemberMsg', 'cron_value' => serialize($message)));
  586. return $insert;
  587. }
  588. /**
  589. * 删除充值记录
  590. * @access public
  591. * @author csdeshang
  592. * @param type $condition 条件
  593. * @return type
  594. */
  595. public function delPdRecharge($condition)
  596. {
  597. return Db::name('pdrecharge')->where($condition)->delete();
  598. }
  599. /**
  600. * 取得提现列表
  601. * @access public
  602. * @author csdeshang
  603. * @param type $condition 条件
  604. * @param type $pagesize 页面
  605. * @param type $fields 字段
  606. * @param type $order 排序
  607. * @param type $limit 限制
  608. * @return type
  609. */
  610. public function getPdcashList($condition = array(), $pagesize = '', $fields = '*', $order = '', $limit = 0)
  611. {
  612. if ($pagesize) {
  613. $pdcash_list_paginate = Db::name('pdcash')->where($condition)->field($fields)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  614. $this->page_info = $pdcash_list_paginate;
  615. return $pdcash_list_paginate->items();
  616. } else {
  617. return Db::name('pdcash')->where($condition)->field($fields)->order($order)->limit($limit)->select()->toArray();
  618. }
  619. }
  620. /**
  621. * 添加提现记录
  622. * @access public
  623. * @author csdeshang
  624. * @param type $data 数据
  625. * @return bool
  626. */
  627. public function addPdcash($data)
  628. {
  629. return Db::name('pdcash')->insertGetId($data);
  630. }
  631. /**
  632. * 编辑提现记录
  633. * @access public
  634. * @author csdeshang
  635. * @param type $data 数据
  636. * @param type $condition 条件
  637. * @return bool
  638. */
  639. public function editPdcash($data, $condition = array())
  640. {
  641. return Db::name('pdcash')->where($condition)->update($data);
  642. }
  643. /**
  644. * 取得单条提现信息
  645. * @access public
  646. * @author csdeshang
  647. * @param type $condition 条件
  648. * @param type $fields 字段
  649. * @return type
  650. */
  651. public function getPdcashInfo($condition = array(), $fields = '*')
  652. {
  653. return Db::name('pdcash')->where($condition)->field($fields)->find();
  654. }
  655. /**
  656. * 删除提现记录
  657. * @access public
  658. * @author csdeshang
  659. * @param type $condition 条件
  660. * @return type
  661. */
  662. public function delPdcash($condition)
  663. {
  664. return Db::name('pdcash')->where($condition)->delete();
  665. }
  666. }