StatKdController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\stat\classes\StatKdClass;
  5. use biz\stat\classes\StatRefundClass;
  6. use bizGhs\order\classes\OrderClass;
  7. use bizGhs\order\models\Order;
  8. use bizGhs\order\models\RefundOrder;
  9. use yii\console\Controller;
  10. use Yii;
  11. class StatKdController extends Controller
  12. {
  13. //销售数据更新 ./yii stat-kd/update
  14. public function actionUpdate()
  15. {
  16. ini_set('memory_limit', '2045M');
  17. set_time_limit(0);
  18. $sql = 'TRUNCATE `xhStatKd`;TRUNCATE `xhStatKdMonth`;';
  19. Yii::$app->db->createCommand($sql)->execute();
  20. $query = new \yii\db\Query();
  21. $query->from(Order::tableName());
  22. foreach ($query->batch() as $batch) {
  23. foreach ($batch as $order) {
  24. $status = $order['status'] ?? 0;
  25. if ($status == 1 || $status == 5) {
  26. continue;
  27. }
  28. $payWay = $order['payWay'] ?? 0;
  29. $amount = $order['actPrice'] ?? 0;
  30. $refundPrice = $order['refundPrice'] ?? 0;
  31. if ($refundPrice > 0) {
  32. $amount = bcadd($amount, $refundPrice, 2);
  33. }
  34. $shopId = $order['shopId'] ?? 0;
  35. $shop = ShopClass::getLockById($shopId);
  36. if (empty($shop)) {
  37. continue;
  38. }
  39. $date = date('Ymd', strtotime($order['addTime']));
  40. StatKdClass::replace($shop, $amount, $payWay, $date);
  41. }
  42. }
  43. $sql = 'TRUNCATE `xhStatRefund`;TRUNCATE `xhStatRefundMonth`;';
  44. Yii::$app->db->createCommand($sql)->execute();
  45. $query = new \yii\db\Query();
  46. $query->from(RefundOrder::tableName());
  47. foreach ($query->batch() as $batch) {
  48. foreach ($batch as $refund) {
  49. $relateOrderSn = $refund['relateOrderSn'] ?? '';
  50. $order = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
  51. $payWay = $order->payWay ?? 0;
  52. $shopId = $refund['shopId'] ?? 0;
  53. $shop = ShopClass::getLockById($shopId);
  54. $amount = $refund['refundPrice'] ?? 0;
  55. $date = date('Ymd', strtotime($refund['addTime']));
  56. StatRefundClass::replace($shop, $payWay, $amount, $date);
  57. }
  58. }
  59. }
  60. }