handler.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace task;
  3. use Exception;
  4. class handler
  5. {
  6. public function refill_order_stat($condition)
  7. {
  8. try
  9. {
  10. $items = Model('')->table('refill_order,vr_order')
  11. ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts, order_state')
  12. ->join('inner')
  13. ->on('refill_order.order_id=vr_order.order_id')
  14. ->where($condition)
  15. ->group('order_state')
  16. ->select();
  17. $all = [];
  18. $data['order_count'] = $data['refill_amounts'] = $data['channel_amounts'] = $data['mch_amounts'] = 0;
  19. $sending = $success = $cancel = $data;
  20. foreach ($items as $item)
  21. {
  22. if ($item['order_state'] == ORDER_STATE_SEND) {
  23. $sending = $item;
  24. } elseif ($item['order_state'] == ORDER_STATE_SUCCESS) {
  25. $success = $item;
  26. } elseif ($item['order_state'] == ORDER_STATE_CANCEL) {
  27. $cancel = $item;
  28. }
  29. $all['order_count'] += $item['order_count'];
  30. $all['refill_amounts'] += ncPriceFormat($item['refill_amounts']);
  31. $all['channel_amounts'] += ncPriceFormat($item['channel_amounts']);
  32. $all['mch_amounts'] += ncPriceFormat($item['mch_amounts']);
  33. }
  34. $result = ['all' => $all, 'sending' => $sending, 'success' => $success, 'cancel' => $cancel];
  35. return [true,$result];
  36. }
  37. catch (Exception $ex)
  38. {
  39. return [false,false];
  40. }
  41. }
  42. public function refill_order_stat_title($condition)
  43. {
  44. return md5("refill_order_stat-".serialize($condition));
  45. }
  46. }