EnergyWalletTradeController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Http\Controllers\Admin\Energy;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models\Energy\EnergyWalletTradeList;
  7. class EnergyWalletTradeController extends Controller
  8. {
  9. public $ProcessStatus = ['6' => '能量钱包未启用','7' => '金额无对应套餐','8' => '下单中','9' => '下单成功','1' => '待下单','5' => '能量钱包未配置私钥','4' => '下单失败'];
  10. public function index(Request $request)
  11. {
  12. return view('admin.energy.trade.index');
  13. }
  14. //列表
  15. public function getData(Request $request)
  16. {
  17. $model = EnergyWalletTradeList::where(function($query) use ($request){
  18. if ($request->tx_hash != '') {
  19. $query->where('tx_hash', 'like' ,"%" . $request->tx_hash ."%");
  20. }
  21. if ($request->transferfrom_address != '') {
  22. $query->where('transferfrom_address', 'like' ,"%" . $request->transferfrom_address ."%");
  23. }
  24. if ($request->transferto_address != '') {
  25. $query->where('transferto_address', 'like' ,"%" . $request->transferto_address ."%");
  26. }
  27. });
  28. $count = $model->count();
  29. $limit = $request->limit ?? 15;
  30. $offset = $request->page ? ($request->page - 1) * $limit : 0;
  31. $data = $model->limit($limit)->offset($offset)->orderBy('rid','desc')->get();
  32. $data = $data->map(function($query){
  33. $query->process_status = $this->ProcessStatus[$query->process_status];
  34. $query->timestamp = date('Y-m-d H:i:s', floor($query->timestamp / 1000));
  35. return $query;
  36. });
  37. return ['code' => '0', 'data' => $data, 'count' => $count];
  38. }
  39. //重新补发
  40. public function reorder(Request $request)
  41. {
  42. $data = EnergyWalletTradeList::where('rid', $request->rid)->first();
  43. if(empty($data)){
  44. return $this->responseData(400, '交易数据不存在');
  45. }
  46. if(!in_array($data->process_status,[4,5,6,7])){
  47. return $this->responseData(400, '状态为-失败,才能补发');
  48. }
  49. DB::beginTransaction();
  50. try {
  51. $data->process_status = 1; //重新处理
  52. $data->tg_notice_status_send = 'N';
  53. $data->save();
  54. DB::commit();
  55. return $this->responseData(200, '补发成功');
  56. } catch (\Exception $e) {
  57. DB::rollBack();
  58. return $this->responseData(400, '补发失败'.$e->getMessage());
  59. }
  60. }
  61. }