TestController.php 18 KB

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