链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
7.4 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class Statistics extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'command:statistics';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Command description';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. bcscale(4);
  36. $stores = DB::table('lanzu_store')->orderBy('id', 'desc')->get()->toArray();
  37. foreach ($stores as $key => &$store) {
  38. // 旧订单
  39. $orderAmountOld1 = DB::table('ims_cjdc_order as ord')
  40. ->selectRaw('SUM(ord.money) AS total')
  41. ->leftJoin('ims_cjdc_order_main as main', 'main.id', '=', 'ord.order_main_id')
  42. ->whereIn('main.state', [4,5,10])
  43. ->where('ord.store_id', '=', $store->id)
  44. ->where('main.type', '=', 1)
  45. ->first();
  46. $orderAmountOld2 = DB::table('ims_cjdc_order as ord')
  47. ->selectRaw('SUM(ord.money) AS total')
  48. ->leftJoin('ims_cjdc_order_main as main', 'main.id', '=', 'ord.order_main_id')
  49. ->whereIn('main.dm_state', [2])
  50. ->where('ord.store_id', '=', $store->id)
  51. ->where('main.type', '=', 4)
  52. ->first();
  53. $orderAmountOldTotal = bcadd($orderAmountOld1->total, $orderAmountOld2->total);
  54. // 新订单
  55. $orderAmountNew = DB::table('lanzu_order as ord')
  56. ->selectRaw('SUM(ord.money) AS total')
  57. ->leftJoin('lanzu_order_main as main', 'main.global_order_id', '=', 'ord.order_main_id')
  58. ->whereIn('main.state', [4,5,10])
  59. ->where('ord.store_id', '=', $store->id)
  60. ->where('main.created_at', '>=', 1600444800)
  61. ->first();
  62. // 旧提现
  63. $withdrawOld = DB::table('ims_cjdc_withdrawal')
  64. ->selectRaw('SUM(tx_cost) AS total')
  65. ->where('state', '=', 2)
  66. ->where('store_id', '=', $store->id)
  67. ->first();
  68. // 新提现
  69. $withdrawNew = DB::table('lanzu_store_withdrawal')
  70. ->selectRaw('SUM(real_cash) AS total')
  71. ->where('state', '=', 2)
  72. ->where('store_id', '=', $store->id)
  73. ->where('created_at', '>=', 1600444800)
  74. ->first();
  75. // 旧奖励
  76. $awardOld = DB::table('ims_cjdc_store_account')
  77. ->selectRaw('SUM(money) AS total')
  78. ->where(function($query) {
  79. $query->where('note', '=', '新用户下单成功,平台奖励')
  80. ->orWhere('note', '=', '用户下单成功,平台奖励');
  81. })
  82. ->where('store_id', '=', $store->id)
  83. ->first();
  84. // 新奖励
  85. $mod = $store->user_id % 5;
  86. $awardNew = DB::table('lanzu_financial_record_'.$mod)
  87. ->selectRaw('SUM(money) AS total')
  88. ->where('user_id', '=', $store->user_id)
  89. ->where('user_type', '=', 5)
  90. ->whereIn('money_type', [4,5])
  91. ->where('created_at', '>=', 1600444800)
  92. ->first();
  93. $withdrawTotal = bcadd($withdrawOld->total, $withdrawNew->total);
  94. $result = bcadd($orderAmountOldTotal, $orderAmountNew->total);
  95. $result = bcadd($result, $awardOld->total);
  96. $result = bcadd($result, $awardNew->total);
  97. $result = bcsub($result, $withdrawTotal);
  98. // 余额
  99. $balance = DB::table('lanzu_user_balance')
  100. ->where('source_id', '=', $store->user_id)
  101. ->where('user_type', '=', 5)
  102. ->first();
  103. var_dump(
  104. 'store_id : ' . $store->id
  105. . ' / user_id : ' . $store->user_id
  106. . ' / order_amount : ' . bcadd($orderAmountOldTotal,$orderAmountNew->total)
  107. . ' / order_old : ' . ($orderAmountOldTotal)
  108. . ' / order_new : ' . ($orderAmountNew->total)
  109. . ' / award_total : ' . bcadd($awardOld->total, $awardNew->total)
  110. . ' / award_old : ' . ($awardOld->total)
  111. . ' / award_new : ' . ($awardNew->total)
  112. . ' / withdraw_total : ' . bcadd($withdrawOld->total, $withdrawNew->total)
  113. . ' / withdraw_old : ' . $withdrawOld->total
  114. . ' / withdraw_new : ' . $withdrawNew->total
  115. . ' / result : '.$result
  116. . ' / balance : '.$balance->balance
  117. );
  118. }
  119. // // 查询店铺收入列表
  120. // $orderAmount = DB::table('lanzu_order as ord')
  121. // ->selectRaw('SUM(ord.money) AS total_amount, ord.store_id, s.user_id')
  122. // ->leftJoin('lanzu_order_main as main', 'main.global_order_id', '=', 'ord.order_main_id')
  123. // ->leftJoin('lanzu_store as s', 's.id', '=', 'ord.store_id')
  124. // ->whereIn('main.state', [4,5,10])
  125. // ->where('store_id', '!=', 0)
  126. // ->groupBy('ord.store_id')
  127. // // ->limit(2)
  128. // ->get()->toArray();
  129. // $withdraws = [];
  130. // $awards = [];
  131. // foreach ($orderAmount as $k => &$item) {
  132. //
  133. // $tmp = DB::table('lanzu_store_withdrawal')
  134. // ->selectRaw('SUM(real_cash) AS total_withdraw')
  135. // ->where('state', '=', 2)
  136. // ->where('store_id', '=', $item->store_id)
  137. // ->first();
  138. //
  139. // $withdraws[$item->store_id] = $tmp->total_withdraw ? $tmp->total_withdraw : 0;
  140. //
  141. // $awardOld = DB::table('ims_cjdc_store_account')
  142. // ->selectRaw('SUM(money) AS total_award')
  143. // ->where(function($query) {
  144. // $query->where('note', '=', '新用户下单成功,平台奖励')
  145. // ->orWhere('note', '=', '用户下单成功,平台奖励');
  146. // })
  147. // ->where('store_id', '=', $item->store_id)
  148. // ->first();
  149. //
  150. // $mod = $item->user_id % 5;
  151. // $awardNew = DB::table('lanzu_financial_record_'.$mod)
  152. // ->selectRaw('SUM(money) AS total_award')
  153. // ->where('user_id', '=', $item->user_id)
  154. // ->where('user_type', '=', 5)
  155. // ->whereIn('money_type', [4,5])
  156. // ->where('created_at', '>=', 1600444800)
  157. // ->first();
  158. //
  159. // $awards[$item->store_id] = floatval($awardOld->total_award+$awardNew->total_award);
  160. //
  161. // $result = $item->total_amount+$awards[$item->store_id]-$withdraws[$item->store_id];
  162. // var_dump('store_id : ' . $item->store_id . ' / order_amount : ' . $item->total_amount . ' / award : ' . $awards[$item->store_id] . ' / withdraw : ' . $withdraws[$item->store_id] . ' / result : '.$result);
  163. // }
  164. // var_dump($withdraws);
  165. // var_dump($awards);
  166. // dd($orderAmount);
  167. }
  168. }