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