EnergyQuickOrderController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\EnergyQuickOrder;
  7. use App\Models\Telegram\TelegramBot;
  8. class EnergyQuickOrderController extends Controller
  9. {
  10. public $status = ['6' => '能量钱包未启用','7' => '金额无对应套餐','8' => '下单中','9' => '下单成功','1' => '待下单','5' => '能量钱包未配置私钥','4' => '下单失败'];
  11. public function index(Request $request)
  12. {
  13. $status = $this->status;
  14. $botData = TelegramBot::pluck('bot_username','rid');
  15. return view('admin.energy.quick.index',compact("status","botData"));
  16. }
  17. //列表
  18. public function getData(Request $request)
  19. {
  20. $model = EnergyQuickOrder::from('energy_quick_order as a')
  21. ->join('telegram_bot as b','a.bot_rid','b.rid')
  22. ->where(function($query) use ($request){
  23. if ($request->bot_rid != '') {
  24. $query->where('b.bot_rid', $request->bot_rid);
  25. }
  26. if ($request->wallet_addr != '') {
  27. $query->where('wallet_addr', 'like' ,"%" . $request->wallet_addr ."%");
  28. }
  29. });
  30. $count = $model->count();
  31. $limit = $request->limit ?? 15;
  32. $offset = $request->page ? ($request->page - 1) * $limit : 0;
  33. $data = $model->limit($limit)->offset($offset)->select('a.*','b.bot_token','b.bot_firstname','b.bot_username')->orderBy('a.rid','desc')->get();
  34. $data = $data->map(function($query){
  35. $query->status = $this->status[$query->status];
  36. return $query;
  37. });
  38. return ['code' => '0', 'data' => $data, 'count' => $count];
  39. }
  40. //重新补发
  41. public function reorder(Request $request)
  42. {
  43. $data = EnergyQuickOrder::where('rid', $request->rid)->first();
  44. if(empty($data)){
  45. return $this->responseData(400, '交易数据不存在');
  46. }
  47. if(!in_array($data->status,[4,5,6,7])){
  48. return $this->responseData(400, '状态为-失败,才能补发');
  49. }
  50. DB::beginTransaction();
  51. try {
  52. $data->status = 1; //重新处理
  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. }