Predeposit.php 30 KB

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