TestController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <?php
  2. namespace pt\controllers;
  3. use biz\sj\services\MerchantExtendService;
  4. use biz\sj\services\MerchantService;
  5. use bizGhs\custom\classes\CustomClass;
  6. use bizGhs\order\classes\OrderClass;
  7. use bizGhs\shop\classes\ShopAdminClass;
  8. use bizGhs\shop\classes\ShopClass;
  9. use bizHd\message\services\InformAdminService;
  10. use bizHd\order\services\OrderService;
  11. use bizHd\saas\classes\ApplyClass;
  12. use bizHd\user\services\UserService;
  13. use bizHd\wx\classes\WxOpenClass;
  14. use bizHd\wx\services\WxOpenService;
  15. use common\components\dateUtil;
  16. use common\components\dict;
  17. use common\components\mapUtil;
  18. use Overtrue\Pinyin\Pinyin;
  19. use Yii;
  20. use common\components\wxUtil;
  21. use common\components\miniUtil;
  22. use bizHd\order\classes\OrderClass as HdOrderClass;
  23. class TestController extends PublicController
  24. {
  25. //收入
  26. public function actionIncome()
  27. {
  28. $searchTime = 'thisMonth';
  29. $startTime = $get['startTime'] ?? '';
  30. $endTime = $get['endTime'] ?? '';
  31. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  32. $start = $period['startTime'];
  33. $end = $period['endTime'];
  34. $currentStartDate = date('Y-m-d', strtotime($start));
  35. $currentEndDate = date('Y-m-d', strtotime($end));
  36. $currentStartTime = $currentStartDate . ' 00:00:00';
  37. $currentEndTime = $currentEndDate . ' 23:59:59';
  38. $mainId = 4836;
  39. $pfIncome = 0;
  40. $pfSendCost = 0;
  41. $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
  42. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  43. print_r($where);
  44. $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
  45. if (!empty($ghsOrderList)) {
  46. foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
  47. $actPrice = $ghsOrder['actPrice'] ?? 0;
  48. $sendCost = $ghsOrder['sendCost'] ?? 0;
  49. $pfIncome = bcadd($pfIncome, $actPrice, 2);
  50. $pfSendCost = bcadd($pfSendCost, $sendCost, 2);
  51. }
  52. }
  53. echo ' ' . $pfIncome . ' ';
  54. echo "==================";
  55. //零售开单
  56. $lsIncome = 0;
  57. $lsSendCost = 0;
  58. $lsServiceFee = 0;
  59. $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
  60. $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  61. $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
  62. foreach ($hdOrderList as $hdKey => $hdOrder) {
  63. $actPrice = $hdOrder['mainPay'] ?? 0;
  64. $serviceFee = $hdOrder['serviceFee'] ?? 0;
  65. $sendCost = $hdOrder['sendCost'] ?? 0;
  66. $lsIncome = bcadd($actPrice, $lsIncome, 2);
  67. //退款取消的先不计算成本
  68. if ($actPrice > 0) {
  69. $lsSendCost = bcadd($lsSendCost, $sendCost, 2);
  70. $lsServiceFee = bcadd($lsServiceFee, $serviceFee, 2);
  71. }
  72. }
  73. echo ' 零售收入:'.$lsIncome.' ';
  74. $shopId = 4892;
  75. $shop = ShopClass::getById($shopId, true);
  76. $mainId = $shop->mainId ?? 0;
  77. //批发开单 pf 零售开单 ls 批发结账 pfJz 零售尾款 lsWk
  78. $searchTime = 'thisMonth';
  79. $startTime = $get['startTime'] ?? '';
  80. $endTime = $get['endTime'] ?? '';
  81. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  82. $start = $period['startTime'];
  83. $end = $period['endTime'];
  84. $currentStartDate = date('Y-m-d', strtotime($start));
  85. $currentEndDate = date('Y-m-d', strtotime($end));
  86. $currentStartTime = $currentStartDate . ' 00:00:00';
  87. $currentEndTime = $currentEndDate . ' 23:59:59';
  88. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId, 'isPt' => 0], null, '*', 'id', true);
  89. $kf = [];
  90. if (!empty($staffList)) {
  91. foreach ($staffList as $staff) {
  92. $name = $staff->name ?? '';
  93. $staffId = $staff->id ?? 0;
  94. $kf[$staffId]['name'] = $name;
  95. $kf[$staffId]['key'] = $staffId;
  96. $kf[$staffId]['num'] = 0;
  97. $kf[$staffId]['amount'] = 0;
  98. $kf[$staffId]['itemList']['pf'] = ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0];
  99. $kf[$staffId]['itemList']['ls'] = ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0];
  100. $kf[$staffId]['itemList']['pfJz'] = ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0];
  101. $kf[$staffId]['itemList']['lsWk'] = ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0];
  102. }
  103. }
  104. $incomeList = [
  105. //系统收入
  106. 'system' => [
  107. 'amount' => 0,
  108. 'num' => 0,
  109. 'name' => '系统收款',
  110. 'category' => [
  111. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  112. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  113. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  114. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  115. ],
  116. ],
  117. 'kfWx' => [
  118. 'amount' => 0,
  119. 'num' => 0,
  120. 'name' => '员工收款',
  121. 'class' => $kf,
  122. 'category' => [
  123. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  124. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  125. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  126. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  127. ]
  128. ],
  129. 'debt' => [
  130. 'amount' => 0,
  131. 'num' => 0,
  132. 'name' => '欠款',
  133. 'category' => [
  134. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  135. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  136. ],
  137. ],
  138. 'debtClear' => [
  139. 'amount' => 0,
  140. 'num' => 0,
  141. 'name' => '已结欠款',
  142. 'category' => [
  143. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  144. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  145. ],
  146. ],
  147. 'cash' => [
  148. 'amount' => 0,
  149. 'name' => '现金',
  150. 'num' => 0,
  151. 'category' => [
  152. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  153. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  154. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  155. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  156. ],
  157. ],
  158. 'aliPay' => [
  159. 'amount' => 0,
  160. 'num' => 0,
  161. 'name' => '支付宝',
  162. 'category' => [
  163. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  164. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  165. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  166. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  167. ],
  168. ],
  169. 'bankCard' => [
  170. 'amount' => 0,
  171. 'name' => '银行卡',
  172. 'num' => 0,
  173. 'category' => [
  174. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  175. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  176. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  177. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  178. ],
  179. ],
  180. 'mt' => ['amount' => 0, 'num' => 0, 'name' => '美团'],
  181. 'other' => [
  182. 'amount' => 0,
  183. 'num' => 0,
  184. 'name' => '其它',
  185. 'category' => [
  186. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  187. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  188. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  189. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  190. ],
  191. ],
  192. ];
  193. $incomeList = [];
  194. //批发开单
  195. $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
  196. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  197. print_r($where);
  198. $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
  199. $ghsTotal = 0;
  200. $defaultTotal = 0;
  201. if (!empty($ghsOrderList)) {
  202. foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
  203. $payWay = $ghsOrder['payWay'] ?? 0;
  204. $actPrice = $ghsOrder['actPrice'] ?? 0;
  205. $ghsTotal = bcadd($ghsTotal, $actPrice, 2);
  206. $getStaffId = $ghsOrder['getStaffId'] ?? 0;
  207. $debtPrice = $ghsOrder['debtPrice'] ?? 0;
  208. $remainDebtPrice = $ghsOrder['remainDebtPrice'] ?? 0;
  209. $onlinePay = $ghsOrder['onlinePay'] ?? dict::getDict('onlinePay', 'not');
  210. if ($debtPrice > 0) {
  211. if ($remainDebtPrice > 0) {
  212. $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $actPrice, 2);
  213. $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
  214. $incomeList['debt']['category']['pf']['amount'] = bcadd($incomeList['debt']['category']['pf']['amount'], $actPrice, 2);
  215. $incomeList['debt']['category']['pf']['num'] = bcadd($incomeList['debt']['category']['pf']['num'], 1);
  216. } else {
  217. $incomeList['debtClear']['amount'] = bcadd($incomeList['debtClear']['amount'], $actPrice, 2);
  218. $incomeList['debtClear']['num'] = bcadd($incomeList['debtClear']['num'], 1);
  219. $incomeList['debtClear']['category']['pf']['amount'] = bcadd($incomeList['debtClear']['category']['pf']['amount'], $actPrice, 2);
  220. $incomeList['debtClear']['category']['pf']['num'] = bcadd($incomeList['debtClear']['category']['pf']['num'], 1);
  221. }
  222. } else {
  223. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  224. //使用在线支付
  225. $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
  226. $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
  227. $incomeList['system']['category']['pf']['amount'] = bcadd($incomeList['system']['category']['pf']['amount'], $actPrice, 2);
  228. $incomeList['system']['category']['pf']['num'] = bcadd($incomeList['system']['category']['pf']['num'], 1);
  229. } else {
  230. //使用非在线支付
  231. switch ($payWay) {
  232. case dict::getDict('payWay', 'wxPay'):
  233. //员工微信总共收了多少笔多少钱
  234. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
  235. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  236. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  237. $incomeList['kfWx']['category']['pf']['amount'] = bcadd($incomeList['kfWx']['category']['pf']['amount'], $actPrice, 2);
  238. $incomeList['kfWx']['category']['pf']['num'] = bcadd($incomeList['kfWx']['category']['pf']['num'], 1);
  239. //每个客服总共收了多少笔多少钱
  240. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  241. $incomeList['kfWx']['class'][$getStaffId]['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $actPrice, 2));
  242. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  243. }
  244. //每个客服收的明细
  245. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf'])) {
  246. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['amount'], $actPrice, 2));
  247. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['num'], 1);
  248. }
  249. break;
  250. case dict::getDict('payWay', 'alipay'):
  251. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  252. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  253. $incomeList['aliPay']['category']['pf']['amount'] = bcadd($incomeList['aliPay']['category']['pf']['amount'], $actPrice, 2);
  254. $incomeList['aliPay']['category']['pf']['num'] = bcadd($incomeList['aliPay']['category']['pf']['num'], 1);
  255. break;
  256. case dict::getDict('payWay', 'cash'):
  257. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
  258. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  259. $incomeList['cash']['category']['pf']['amount'] = bcadd($incomeList['cash']['category']['pf']['amount'], $actPrice, 2);
  260. $incomeList['cash']['category']['pf']['num'] = bcadd($incomeList['cash']['category']['pf']['num'], 1);
  261. break;
  262. case dict::getDict('payWay', 'bankCard'):
  263. $incomeList['bankCard']['amount'] = bcadd($incomeList['bankCard']['amount'], $actPrice, 2);
  264. $incomeList['bankCard']['num'] = bcadd($incomeList['bankCard']['num'], 1);
  265. $incomeList['bankCard']['category']['pf']['amount'] = bcadd($incomeList['bankCard']['category']['pf']['amount'], $actPrice, 2);
  266. $incomeList['bankCard']['category']['pf']['num'] = bcadd($incomeList['bankCard']['category']['pf']['num'], 1);
  267. break;
  268. case dict::getDict('payWay', 'unknown'):
  269. $incomeList['other']['amount'] = bcadd($incomeList['other']['amount'], $actPrice, 2);
  270. $incomeList['other']['num'] = bcadd($incomeList['other']['num'], 1);
  271. $incomeList['other']['category']['pf']['amount'] = bcadd($incomeList['other']['category']['pf']['amount'], $actPrice, 2);
  272. $incomeList['other']['category']['pf']['num'] = bcadd($incomeList['other']['category']['pf']['num'], 1);
  273. break;
  274. default:
  275. $defaultTotal = bcadd($defaultTotal, $actPrice, 2);
  276. }
  277. }
  278. }
  279. }
  280. }
  281. $total = 0;
  282. foreach ($incomeList as $i) {
  283. $current = $i['amount'] ?? 0;
  284. $total = bcadd($current, $total, 2);
  285. }
  286. echo ' default:'.$defaultTotal.' ';
  287. echo ' ghsTotal:' . $ghsTotal . ' ';
  288. echo ' total:' . $total . ' ';
  289. print_r($incomeList);
  290. die;
  291. }
  292. //即时配送
  293. public function actionGetBindAccount()
  294. {
  295. $merchant = WxOpenClass::getGhsWxInfo();
  296. $isOpen = 2;
  297. $r = miniUtil::getBindAccount($merchant, $isOpen);
  298. dd($r);
  299. }
  300. public function actionDada()
  301. {
  302. //https://github.com/wanDoubleMing/dada_openapi_php
  303. //初始化一个配置文件
  304. $dada = Yii::getAlias("@vendor/dada/");
  305. require_once $dada . 'api/addOrderApi.php';
  306. require_once $dada . 'client/dadaRequestClient.php';
  307. require_once $dada . 'client/dadaResponse.php';
  308. require_once $dada . 'config/config.php';
  309. require_once $dada . 'model/orderModel.php';
  310. // isOnline 判断是否是测试环境,会有不同的域名等
  311. $isOnline = false;
  312. //商户id
  313. $sourceId = 73753;
  314. $shopNo = 11047059;
  315. // 初始化一个config
  316. $config = new \Config($sourceId, $isOnline);
  317. //3.domain文件新建一个model,并初始化
  318. $orderModel = new \OrderModel();
  319. $orderModel->setShopNo($shopNo);
  320. $orderModel->setOriginId('2020043017180001');
  321. $orderModel->setCityCode('021');
  322. $orderModel->setCargoPrice(10);
  323. $orderModel->setIsPrepay(0);
  324. $orderModel->setReceiverName('测试达达');
  325. $orderModel->setReceiverAddress('上海市崇明岛');
  326. $orderModel->setReceiverLat(31.63);
  327. $orderModel->setReceiverLng(121.41);
  328. $orderModel->setReceiverPhone('15280215347');
  329. $orderModel->setCallback('https://api.saas.huaml.com/express/callback');
  330. // api主要有2个参数,一个是url, 一个是业务参数
  331. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  332. //5.初始化客户端,并调用rpc
  333. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  334. $resp = $dada_client->makeRequest();
  335. echo json_encode($resp);
  336. }
  337. public function actionRabbit()
  338. {
  339. $orderId = 214752;
  340. $order = OrderService::getById($orderId);
  341. $sjId = $order['sjId'];
  342. $openMerchant = WxOpenService::getWxInfo();
  343. $merchant = MerchantService::getMerchantById($sjId);
  344. $shopId = $merchant['defaultShopId'];
  345. $params = ['sourceType' => $order['sourceType'], 'miniAppId' => $openMerchant['miniAppId'], 'orderId' => $orderId];
  346. $type = 'income';
  347. InformAdminService::addInform($shopId, $type, $params);
  348. }
  349. //添加优惠券 ssh 2020.5.5
  350. public function actionAddCoupon()
  351. {
  352. $merchant = MerchantService::getMerchantById(12358);
  353. $user = UserService::getById(12543444);
  354. UserService::focus($user, $merchant);
  355. }
  356. public function actionGetUnionId()
  357. {
  358. $merchant = MerchantService::getMerchantById(12358);
  359. $extend = MerchantExtendService::getBySjId(12358);
  360. $mcId = $extend['wxPayMerchantId'];
  361. $orderId = '200512145420123581254345688252';
  362. miniUtil::getPaidUnionId($merchant, 'o-hXO4qOzIVbUNVucoFzEiArOz5k', $mcId, $orderId, 0);
  363. }
  364. public function actionCalc()
  365. {
  366. $dis = mapUtil::calculateDistance('116.308479', '39.983171', '116.328479', '39.973171');
  367. echo $dis;
  368. }
  369. }