CsController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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', 'read'];
  43. public function actionRead()
  44. {
  45. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  46. $currentDirectory = getcwd();
  47. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
  48. $spreadsheet = \PHPExcel_IOFactory::load($currentDirectory . "/123.xlsx");
  49. //print_r($objPHPExcel->getActiveSheet()->toArray());
  50. // foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) {
  51. // foreach ($row->getCellIterator() as $cell) {
  52. // if (!$cell->getValue()) { // 跳过空白单元格
  53. // continue;
  54. // }
  55. // echo 'Cell ' . $cell->getColumn() . $cell->getRow() . ' = ' . $cell->getValue() . '<br />';
  56. // }
  57. // }
  58. // 获取活动工作表
  59. $worksheet = $spreadsheet->getActiveSheet();
  60. // 遍历每一行
  61. foreach ($worksheet->getRowIterator() as $row) {
  62. $cellIterator = $row->getCellIterator();
  63. $cellIterator->setIterateOnlyExistingCells(FALSE); // 这里设置为迭代所有单元格,包括空单元格
  64. // 遍历每列
  65. $rowData = [];
  66. foreach ($cellIterator as $cell) {
  67. $rowData[] = $cell->getValue();
  68. }
  69. // 输出当前行数据
  70. echo implode(", ", $rowData) . "\n";
  71. }
  72. // // 加载Excel文件
  73. // $spreadsheet = IOFactory::load($filePath);
  74. //
  75. // // 获取活动工作表
  76. // $worksheet = $spreadsheet->getActiveSheet();
  77. //
  78. // // 遍历每一行
  79. // foreach ($worksheet->getRowIterator() as $row) {
  80. // $cellIterator = $row->getCellIterator();
  81. // $cellIterator->setIterateOnlyExistingCells(FALSE); // 这里设置为迭代所有单元格,包括空单元格
  82. //
  83. // // 遍历每列
  84. // $rowData = [];
  85. // foreach ($cellIterator as $cell) {
  86. // $rowData[] = $cell->getValue();
  87. // }
  88. //
  89. // // 输出当前行数据
  90. // echo implode(", ", $rowData) . "\n";
  91. // }
  92. }
  93. public function actionList()
  94. {
  95. $where = [];
  96. $get = Yii::$app->request->get();
  97. $export = 1;
  98. $search = $get['search'] ?? '';
  99. $where['shopId'] = 23580;
  100. $ghsId = $get['ghsId'] ?? 0;
  101. if (!empty($ghsId)) {
  102. $where['ghsId'] = $ghsId;
  103. }
  104. if (!empty($search)) {
  105. if (is_numeric($search) && strlen($search) == 4) {
  106. $where['orderSn'] = ['like', $search];
  107. } else {
  108. $where['ghsName'] = ['like', $search];
  109. }
  110. }
  111. $name = $get['name'] ?? '';
  112. if (!empty($name)) {
  113. $re = strstr($name, 'PH');
  114. if (!empty($re)) {
  115. $where['orderSn'] = $name;
  116. } else {
  117. $where['ghsName'] = ['like', $name];
  118. }
  119. }
  120. $searchTime = 'custom';
  121. $startTime = '2024-07-01';
  122. $endTime = '2024-07-31';
  123. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  124. $where['entryTime'] = ['between', [$period['startTime'], $period['endTime']]];
  125. $cgStaffId = $get['cgStaffId'] ?? 0;
  126. if (!empty($cgStaffId)) {
  127. $where['cgStaffId'] = $cgStaffId;
  128. }
  129. if ($export == 1) {
  130. ini_set('memory_limit', '2045M');
  131. set_time_limit(0);
  132. if (isset($where['entryTime']) == false) {
  133. util::fail('请选时间段');
  134. }
  135. $start = $where['entryTime'][1][0];
  136. $end = $where['entryTime'][1][1];
  137. $monthTime = bcmul(31, 86400);
  138. $startArea = strtotime($start);
  139. $endArea = strtotime($end);
  140. $diff = bcsub($endArea, $startArea);
  141. if ($diff > $monthTime) {
  142. util::fail('最长可导出一个月');
  143. }
  144. }
  145. $data = PurchaseOrderClass::getOrderList($where);
  146. if ($export == 1) {
  147. $this->exportOrderData($data, 23390);
  148. util::stop('');
  149. }
  150. //状态统计,很慢,暂时隐藏
  151. //$statData = PurchaseOrderClass::statNum($this->shopId);
  152. $statData = [
  153. 'allNum' => 0,
  154. 'unPayNum' => 0,
  155. 'unSendNum' => 0,
  156. 'sendingNum' => 0,
  157. 'finishNum' => 0,
  158. ];
  159. $data = array_merge($data, $statData);
  160. echo "<pre>";
  161. print_r($data);
  162. util::stop('');
  163. }
  164. public function exportOrderData($respond, $mainId)
  165. {
  166. $orderList = $respond['list'] ?? [];
  167. if (empty($orderList)) {
  168. util::fail('没有数据需要导出');
  169. }
  170. $orderSnList = array_column($orderList, 'orderSn');
  171. $orderItemData = PurchaseOrderItemClass::getAllByCondition(['orderSn' => ['in', $orderSnList]], null, '*');
  172. $orderItemList = [];
  173. if (!empty($orderItemData)) {
  174. foreach ($orderItemData as $itemInfo) {
  175. $orderSn = $itemInfo['orderSn'] ?? '';
  176. $orderItemList[$orderSn][] = $itemInfo;
  177. }
  178. }
  179. $totalActPrice = 0;
  180. $totalTkPrice = 0;
  181. $totalOnlyTkPrice = 0;
  182. $totalOrderPrice = 0;
  183. foreach ($orderList as $key => $orderInfo) {
  184. $orderSn = $orderInfo['orderSn'] ?? '';
  185. $status = $orderInfo['status'] ?? 0;
  186. $entryTime = $orderInfo['entryTime'] ?? '';
  187. //增加项
  188. $actPrice = $orderInfo['actPrice'] ?? 0;
  189. $tkPrice = $orderInfo['tkPrice'] ?? 0;
  190. $orderPrice = $orderInfo['orderPrice'] ?? 0;
  191. $discountAmount = $orderInfo['discountAmount'] ?? 0;
  192. $packingCharge = $orderInfo['packingCharge'] ?? 0;
  193. $shortCharge = $orderInfo['shortCharge'] ?? 0;
  194. $longCharge = $orderInfo['longCharge'] ?? 0;
  195. $pickCharge = $orderInfo['pickCharge'] ?? 0;
  196. $localCharge = $orderInfo['localCharge'] ?? 0;
  197. if ($status != 4) {
  198. unset($orderList[$key]);
  199. continue;
  200. }
  201. //增加项
  202. if ($actPrice <= 0) {
  203. unset($orderList[$key]);
  204. continue;
  205. }
  206. if ($discountAmount > 0 || $packingCharge > 0 || $shortCharge > 0 || $longCharge > 0 || $pickCharge > 0 || $localCharge > 0) {
  207. echo $orderSn . ' ' . $discountAmount . ' ' . $packingCharge . ' ' . $shortCharge . ' ' . $longCharge . ' ' . $pickCharge . ' ' . $localCharge . "<br/>\n";
  208. }
  209. $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
  210. $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
  211. $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
  212. $itemList = $orderItemList[$orderSn] ?? [];
  213. $orderList[$key]['itemList'] = $itemList;
  214. //增加项
  215. if ($tkPrice > 0) {
  216. $refundList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
  217. if (!empty($refundList)) {
  218. foreach ($refundList as $refundInfo) {
  219. if (isset($refundInfo->refundType) && $refundInfo->refundType == 2) {
  220. $refundPrice = $refundInfo->refundPrice ?? 0;
  221. $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
  222. }
  223. }
  224. }
  225. }
  226. $currentItemPrice = 0;
  227. if (!empty($itemList)) {
  228. foreach ($itemList as $itemData) {
  229. $bigPrice = $itemData['bigPrice'] ?? 0;
  230. $itemNum = $itemData['itemNum'] ?? 0;
  231. $total = bcmul($bigPrice, $itemNum, 2);
  232. $currentItemPrice = bcadd($currentItemPrice, $total, 2);
  233. }
  234. }
  235. $add1 = bcadd($currentItemPrice, $packingCharge, 2);
  236. $add2 = bcadd($add1, $shortCharge, 2);
  237. $add3 = bcadd($add2, $longCharge, 2);
  238. $last = bcsub($add3, $tkPrice, 2);
  239. // if (floatval($last) != floatval($actPrice)) {
  240. // echo $currentItemPrice . ' 优惠:' . $discountAmount . ' 打包:' . $packingCharge . ' 短途:' . $shortCharge . ' 长途:' . $longCharge . ' 提:' . $pickCharge . ' 本:' . $localCharge . ' 实:' . $actPrice . $entryTime . "<br/>\n";
  241. // echo $orderSn . " 不同<br/>\n";
  242. // die;
  243. // }
  244. }
  245. echo "<pre>";
  246. echo '订单金额:' . $totalOrderPrice . ' 实际金额:' . $totalActPrice . ' 退款金额:' . $totalTkPrice . ' 仅退款:' . $totalOnlyTkPrice;
  247. }
  248. }