CsController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\sj\classes\SjClass;
  5. use biz\wx\classes\WxMessageClass;
  6. use bizGhs\book\classes\BookItemClass;
  7. use bizGhs\cg\classes\CgRefundClass;
  8. use bizGhs\order\classes\PurchaseOrderClass;
  9. use bizGhs\order\classes\PurchaseOrderItemClass;
  10. use bizGhs\product\classes\ProductClass;
  11. use bizGhs\shop\classes\ShopClass;
  12. use bizHd\purchase\classes\PurchaseClass;
  13. use common\components\dateUtil;
  14. use common\components\dict;
  15. use common\components\noticeUtil;
  16. use common\components\printUtil;
  17. use common\components\stringUtil;
  18. use common\components\util;
  19. use biz\shop\classes\ShopExtClass;
  20. use Yii;
  21. use biz\shop\classes\MainClass;
  22. use biz\shop\classes\ShopCapitalClass;
  23. use biz\stat\classes\StatCgClass;
  24. use biz\stat\classes\StatCgGhsClass;
  25. use biz\stat\classes\StatOutClass;
  26. use bizGhs\base\classes\BaseClass;
  27. use bizGhs\book\classes\BookCustomClass;
  28. use bizGhs\book\classes\BookItemCustomClass;
  29. use bizGhs\book\classes\BookItemGhsClass;
  30. use bizGhs\cg\classes\CgOrderItemClass;
  31. use bizGhs\cg\classes\CgOrderItemSendClass;
  32. use bizGhs\custom\classes\CustomClass;
  33. use bizGhs\ghs\classes\GhsDebtRecordClass;
  34. use bizGhs\item\classes\CostChangeClass;
  35. use bizGhs\item\classes\ItemClassClass;
  36. use bizGhs\order\traits\OrderTrait;
  37. use bizGhs\shop\classes\ShopAdminClass;
  38. use bizGhs\stock\classes\OnStockRecordClass;
  39. use bizGhs\stock\classes\StockRecordClass;
  40. class CsController extends BaseController
  41. {
  42. public $guestAccess = ['list'];
  43. public function actionList()
  44. {
  45. $where = [];
  46. $get = Yii::$app->request->get();
  47. $export = 1;
  48. $search = $get['search'] ?? '';
  49. $where['shopId'] = 23580;
  50. $ghsId = $get['ghsId'] ?? 0;
  51. if (!empty($ghsId)) {
  52. $where['ghsId'] = $ghsId;
  53. }
  54. if (!empty($search)) {
  55. if (is_numeric($search) && strlen($search) == 4) {
  56. $where['orderSn'] = ['like', $search];
  57. } else {
  58. $where['ghsName'] = ['like', $search];
  59. }
  60. }
  61. $name = $get['name'] ?? '';
  62. if (!empty($name)) {
  63. $re = strstr($name, 'PH');
  64. if (!empty($re)) {
  65. $where['orderSn'] = $name;
  66. } else {
  67. $where['ghsName'] = ['like', $name];
  68. }
  69. }
  70. $searchTime = 'custom';
  71. $startTime = '2024-07-01';
  72. $endTime = '2024-07-31';
  73. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  74. $where['entryTime'] = ['between', [$period['startTime'], $period['endTime']]];
  75. $cgStaffId = $get['cgStaffId'] ?? 0;
  76. if (!empty($cgStaffId)) {
  77. $where['cgStaffId'] = $cgStaffId;
  78. }
  79. if ($export == 1) {
  80. ini_set('memory_limit', '2045M');
  81. set_time_limit(0);
  82. if (isset($where['entryTime']) == false) {
  83. util::fail('请选时间段');
  84. }
  85. $start = $where['entryTime'][1][0];
  86. $end = $where['entryTime'][1][1];
  87. $monthTime = bcmul(31, 86400);
  88. $startArea = strtotime($start);
  89. $endArea = strtotime($end);
  90. $diff = bcsub($endArea, $startArea);
  91. if ($diff > $monthTime) {
  92. util::fail('最长可导出一个月');
  93. }
  94. }
  95. $data = PurchaseOrderClass::getOrderList($where);
  96. if ($export == 1) {
  97. $this->exportOrderData($data, 23390);
  98. util::stop('');
  99. }
  100. //状态统计,很慢,暂时隐藏
  101. //$statData = PurchaseOrderClass::statNum($this->shopId);
  102. $statData = [
  103. 'allNum' => 0,
  104. 'unPayNum' => 0,
  105. 'unSendNum' => 0,
  106. 'sendingNum' => 0,
  107. 'finishNum' => 0,
  108. ];
  109. $data = array_merge($data, $statData);
  110. echo "<pre>";
  111. print_r($data);
  112. util::stop('');
  113. }
  114. public function exportOrderData($respond, $mainId)
  115. {
  116. $orderList = $respond['list'] ?? [];
  117. if (empty($orderList)) {
  118. util::fail('没有数据需要导出');
  119. }
  120. $orderSnList = array_column($orderList, 'orderSn');
  121. $orderItemData = PurchaseOrderItemClass::getAllByCondition(['orderSn' => ['in', $orderSnList]], null, '*');
  122. $orderItemList = [];
  123. if (!empty($orderItemData)) {
  124. foreach ($orderItemData as $itemInfo) {
  125. $orderSn = $itemInfo['orderSn'] ?? '';
  126. $orderItemList[$orderSn][] = $itemInfo;
  127. }
  128. }
  129. $totalActPrice = 0;
  130. $totalTkPrice = 0;
  131. $totalOnlyTkPrice = 0;
  132. $totalOrderPrice = 0;
  133. foreach ($orderList as $key => $orderInfo) {
  134. $orderSn = $orderInfo['orderSn'] ?? '';
  135. $status = $orderInfo['status'] ?? 0;
  136. $entryTime = $orderInfo['entryTime'] ?? '';
  137. //增加项
  138. $actPrice = $orderInfo['actPrice'] ?? 0;
  139. $tkPrice = $orderInfo['tkPrice'] ?? 0;
  140. $orderPrice = $orderInfo['orderPrice'] ?? 0;
  141. $discountAmount = $orderInfo['discountAmount'] ?? 0;
  142. $packingCharge = $orderInfo['packingCharge'] ?? 0;
  143. $shortCharge = $orderInfo['shortCharge'] ?? 0;
  144. $longCharge = $orderInfo['longCharge'] ?? 0;
  145. $pickCharge = $orderInfo['pickCharge'] ?? 0;
  146. $localCharge = $orderInfo['localCharge'] ?? 0;
  147. if ($status != 4) {
  148. unset($orderList[$key]);
  149. continue;
  150. }
  151. //增加项
  152. if ($actPrice <= 0) {
  153. unset($orderList[$key]);
  154. continue;
  155. }
  156. if ($discountAmount > 0 || $packingCharge > 0 || $shortCharge > 0 || $longCharge > 0 || $pickCharge > 0 || $localCharge > 0) {
  157. echo $orderSn . ' ' . $discountAmount . ' ' . $packingCharge . ' ' . $shortCharge . ' ' . $longCharge . ' ' . $pickCharge . ' ' . $localCharge . "<br/>\n";
  158. }
  159. $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
  160. $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
  161. $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
  162. $itemList = $orderItemList[$orderSn] ?? [];
  163. $orderList[$key]['itemList'] = $itemList;
  164. //增加项
  165. if ($tkPrice > 0) {
  166. $refundList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
  167. if (!empty($refundList)) {
  168. foreach ($refundList as $refundInfo) {
  169. if (isset($refundInfo->refundType) && $refundInfo->refundType == 2) {
  170. $refundPrice = $refundInfo->refundPrice ?? 0;
  171. $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
  172. }
  173. }
  174. }
  175. }
  176. $currentItemPrice = 0;
  177. if (!empty($itemList)) {
  178. foreach ($itemList as $itemData) {
  179. $bigPrice = $itemData['bigPrice'] ?? 0;
  180. $itemNum = $itemData['itemNum'] ?? 0;
  181. $total = bcmul($bigPrice, $itemNum, 2);
  182. $currentItemPrice = bcadd($currentItemPrice, $total, 2);
  183. }
  184. }
  185. $add1 = bcadd($currentItemPrice, $packingCharge, 2);
  186. $add2 = bcadd($add1, $shortCharge, 2);
  187. $add3 = bcadd($add2, $longCharge, 2);
  188. $last = bcsub($add3, $tkPrice, 2);
  189. // if (floatval($last) != floatval($actPrice)) {
  190. // echo $currentItemPrice . ' 优惠:' . $discountAmount . ' 打包:' . $packingCharge . ' 短途:' . $shortCharge . ' 长途:' . $longCharge . ' 提:' . $pickCharge . ' 本:' . $localCharge . ' 实:' . $actPrice . $entryTime . "<br/>\n";
  191. // echo $orderSn . " 不同<br/>\n";
  192. // die;
  193. // }
  194. }
  195. echo "<pre>";
  196. echo '订单金额:' . $totalOrderPrice . ' 实际金额:' . $totalActPrice . ' 退款金额:' . $totalTkPrice . ' 仅退款:' . $totalOnlyTkPrice;
  197. }
  198. }