CsController.php 9.9 KB

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