Finance.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xurongyao <763569752@qq.com>
  5. * Date: 2018/6/14 下午5:25
  6. */
  7. namespace app\admin\controller\finance;
  8. use app\admin\controller\AuthController;
  9. use app\models\trade\CashTradeOrder;
  10. use app\models\user\UserMoney;
  11. use app\Request;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\repositories\ShortLetterRepositories;
  14. use app\admin\model\user\{User, UserBill};
  15. use app\admin\model\finance\FinanceModel;
  16. use crmeb\services\{UtilService as Util, JsonService as Json, UtilService};
  17. /**
  18. * 微信充值记录
  19. * Class UserRecharge
  20. * @package app\admin\controller\user
  21. */
  22. class Finance extends AuthController
  23. {
  24. /**
  25. * 显示资金记录
  26. */
  27. public function bill()
  28. {
  29. $list = UserBill::where('type', 'not in', ['gain', 'deduction', 'sign'])
  30. ->where('category', 'not in', 'integral')
  31. ->field(['title', 'type'])
  32. ->group('type')
  33. ->distinct(true)
  34. ->select()
  35. ->toArray();
  36. $this->assign('selectList', $list);
  37. return $this->fetch();
  38. }
  39. /**
  40. * 显示资金记录ajax列表
  41. */
  42. public function billlist()
  43. {
  44. $where = Util::getMore([
  45. ['start_time', ''],
  46. ['end_time', ''],
  47. ['nickname', ''],
  48. ['limit', 20],
  49. ['page', 1],
  50. ['type', ''],
  51. ]);
  52. return Json::successlayui(FinanceModel::getBillList($where));
  53. }
  54. /**
  55. *保存资金监控的excel表格
  56. */
  57. public function save_bell_export()
  58. {
  59. $where = Util::getMore([
  60. ['start_time', ''],
  61. ['end_time', ''],
  62. ['nickname', ''],
  63. ['type', ''],
  64. ]);
  65. FinanceModel::SaveExport($where);
  66. }
  67. /**
  68. * 显示佣金记录
  69. */
  70. public function commission_list()
  71. {
  72. $this->assign('is_layui', true);
  73. return $this->fetch();
  74. }
  75. /**
  76. * 佣金记录异步获取
  77. */
  78. public function get_commission_list()
  79. {
  80. $get = Util::getMore([
  81. ['page', 1],
  82. ['limit', 20],
  83. ['nickname', ''],
  84. ['price_max', ''],
  85. ['price_min', ''],
  86. ['order', ''],
  87. ['excel', ''],
  88. ]);
  89. return Json::successlayui(User::getCommissionList($get));
  90. }
  91. /**
  92. * 显示操作记录
  93. */
  94. public function index3()
  95. {
  96. }
  97. /**
  98. * 佣金详情
  99. */
  100. public function content_info($uid = '')
  101. {
  102. if ($uid == '') return $this->failed('缺少参数');
  103. $this->assign('userinfo', User::getUserinfo($uid));
  104. $this->assign('uid', $uid);
  105. return $this->fetch();
  106. }
  107. /**
  108. * 佣金提现记录个人列表
  109. */
  110. public function get_extract_list($uid = '')
  111. {
  112. if ($uid == '') return Json::fail('缺少参数');
  113. $where = Util::getMore([
  114. ['page', 1],
  115. ['limit', 20],
  116. ['start_time', ''],
  117. ['end_time', ''],
  118. ['nickname', '']
  119. ]);
  120. return Json::successlayui(UserBill::getExtrctOneList($where, $uid));
  121. }
  122. public function cashTrade()
  123. {
  124. return $this->fetch();
  125. }
  126. public function cashTradeList()
  127. {
  128. $where = $where = UtilService::getMore([
  129. ['money_type', ''],
  130. ['trade_uid', ''],
  131. ['order_id', ''],
  132. ['page', 1],
  133. ['limit', 10],
  134. ['status', ''],
  135. ['trade_type', '']
  136. ], $this->request);
  137. $data = CashTradeOrder::getList($where);
  138. $data['data'] = $data['list'];
  139. unset($data['list']);
  140. Json::successlayui($data);
  141. }
  142. public function check($id, $ok, Request $request)
  143. {
  144. $order = CashTradeOrder::where('id', $id)->where('status', 'in', [3, -1])->find();
  145. if (!in_array($ok, ['y', 'n'])) return app('json')->fail('参数错误');
  146. $res = true;
  147. BaseModel::beginTrans();
  148. if ($ok == 'y') {
  149. switch ($order['trade_type']) {
  150. case 1:
  151. if ($order['trade_uid'] != 0)
  152. $res = $res && UserMoney::incomeMoney($order['trade_uid'], $order['money_type'], $order['money_num'], 'buy_success', '购币成功', '购币成功,出售方ID' . $order['uid']);
  153. break;
  154. case 2:
  155. $res = $res && UserMoney::incomeMoney($order['uid'], $order['money_type'], $order['money_num'], 'buy_success', '购币成功', '购币成功,出售方ID' . $order['trade_uid']);
  156. break;
  157. default:
  158. break;
  159. }
  160. $res = $res && CashTradeOrder::where('id', $id)->update(['status' => 1, 'trade_time' => time()])
  161. && CashTradeOrder::brokerage($id);
  162. BaseModel::checkTrans($res);
  163. if ($res) {
  164. if ($order['trade_uid'] === 0) {
  165. $user = \app\models\user\User::getUserInfo($order['uid']);
  166. ShortLetterRepositories::SMSSend($user['phone'], ['code' => 0], 'SUCCESS_TRADE');
  167. }
  168. Json::successful('审核成功');
  169. // return app('json')->success('审核成功');
  170. } else {
  171. return app('json')->fail('审核失败');
  172. }
  173. } else {
  174. switch ($order['trade_type']) {
  175. case 1:
  176. $res = $res && UserMoney::incomeMoney($order['uid'], $order['money_type'], $order['money_num'], 'buy_fail', '购币失败', '购币失败,出售方ID' . $order['uid']);
  177. break;
  178. case 2:
  179. $res = $res && UserMoney::incomeMoney($order['trade_uid'], $order['money_type'], $order['money_num'], 'buy_fail', '购币失败', '购币失败,出售方ID' . $order['trade_uid']);
  180. break;
  181. default:
  182. break;
  183. }
  184. $res = $res && CashTradeOrder::where('id', $id)->update(['status' => 2, 'end_time' => time()]);
  185. BaseModel::checkTrans($res);
  186. if ($res) {
  187. Json::successful('退回成功');
  188. } else {
  189. return app('json')->fail('退回失败');
  190. }
  191. }
  192. }
  193. public function cancel($id, Request $request)
  194. {
  195. $order = CashTradeOrder::get($id);
  196. if ($order['close_time'] && $order['close_time'] < time()) return app('json')->fail('订单已关闭');
  197. if ($order['status'] > 0) return app('json')->fail('订单不可撤销');
  198. BaseModel::beginTrans();
  199. $res = true;
  200. switch ($order['trade_type']) {
  201. case 1:
  202. //退回币
  203. $res = $res && UserMoney::incomeMoney($order['uid'], $order['money_type'], $order['money_num'], 'hang_sale_cancel', '挂卖取消', '挂卖取消,退回钱包');
  204. $res = $res && CashTradeOrder::where('id', $order['id'])->update(['status' => 2]);
  205. break;
  206. case 2:
  207. //
  208. if ($order['trade_uid'])
  209. $res = $res && UserMoney::incomeMoney($order['trade_uid'], $order['money_type'], $order['money_num'], 'hang_buy_cancel', '挂买取消', '挂买取消,退回钱包');
  210. $res = $res && CashTradeOrder::where('id', $order['id'])->update(['status' => 2]);
  211. break;
  212. default:
  213. break;
  214. }
  215. BaseModel::checkTrans($res);
  216. if ($res) {
  217. Json::successful('取消成功');
  218. // return app('json')->success('取消成功');
  219. } else {
  220. return app('json')->fail('取消失败');
  221. }
  222. }
  223. }