Predeposit.php 30 KB

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