TestController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. echo "<pre>";
  29. $searchTime = 'thisMonth';
  30. $startTime = $get['startTime'] ?? '';
  31. $endTime = $get['endTime'] ?? '';
  32. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  33. $start = $period['startTime'];
  34. $end = $period['endTime'];
  35. $currentStartDate = date('Y-m-d', strtotime($start));
  36. $currentEndDate = date('Y-m-d', strtotime($end));
  37. $currentStartTime = $currentStartDate . ' 00:00:00';
  38. $currentEndTime = $currentEndDate . ' 23:59:59';
  39. $shopId = 763;
  40. //$shopId = 4892;
  41. $shop = ShopClass::getById($shopId, true);
  42. $mainId = $shop->mainId ?? 0;
  43. //零售开单
  44. $lsIncome = 0;
  45. $lsSendCost = 0;
  46. $lsServiceFee = 0;
  47. $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
  48. $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  49. $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
  50. foreach ($hdOrderList as $hdKey => $hdOrder) {
  51. $actPrice = $hdOrder['mainPay'] ?? 0;
  52. $serviceFee = $hdOrder['serviceFee'] ?? 0;
  53. $sendCost = $hdOrder['sendCost'] ?? 0;
  54. $lsIncome = bcadd($actPrice, $lsIncome, 2);
  55. //退款取消的先不计算成本
  56. if ($actPrice > 0) {
  57. $lsSendCost = bcadd($lsSendCost, $sendCost, 2);
  58. $lsServiceFee = bcadd($lsServiceFee, $serviceFee, 2);
  59. }
  60. }
  61. echo " <br />零售收入:" . $lsIncome . "<br />";
  62. $incomeList = [];
  63. $an = 0;
  64. //零售开单
  65. $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
  66. $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  67. $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
  68. foreach ($hdOrderList as $hdKey => $hdOrder) {
  69. $payWay = $hdOrder['payWay'] ?? 0;
  70. $mainPay = $hdOrder['mainPay'] ?? 0;
  71. $cash = $hdOrder['cash'] ?? 0;
  72. $actPrice = $hdOrder['mainPay'] ?? 0;
  73. $getStaffId = $hdOrder['getStaffId'] ?? 0;
  74. $debtPrice = $hdOrder['debtPrice'] ?? 0;
  75. $remainDebtPrice = $hdOrder['remainDebtPrice'] ?? 0;
  76. $onlinePay = $hdOrder['onlinePay'] ?? 0;
  77. $fromType = $hdOrder['fromType'] ?? 0;
  78. $an = bcadd($an, $mainPay, 2);
  79. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  80. //使用在线支付
  81. $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $mainPay, 2);
  82. $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
  83. $incomeList['system']['category']['ls']['amount'] = bcadd($incomeList['system']['category']['ls']['amount'], $mainPay, 2);
  84. $incomeList['system']['category']['ls']['num'] = bcadd($incomeList['system']['category']['ls']['num'], 1);
  85. if ($cash > 0) {
  86. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $cash, 2);
  87. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  88. $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $cash, 2);
  89. $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
  90. }
  91. } else {
  92. if ($fromType == dict::getDict('fromType', 'mt')) {
  93. //美团!!!
  94. $incomeList['mt']['amount'] = bcadd($incomeList['mt']['amount'], $actPrice, 2);
  95. $incomeList['mt']['num'] = bcadd($incomeList['mt']['num'], 1);
  96. } else {
  97. //非美团!!!
  98. if ($debtPrice > 0) {
  99. if ($remainDebtPrice > 0) {
  100. $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $debtPrice, 2);
  101. $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
  102. $incomeList['debt']['category']['ls']['amount'] = bcadd($incomeList['debt']['category']['ls']['amount'], $debtPrice, 2);
  103. $incomeList['debt']['category']['ls']['num'] = bcadd($incomeList['debt']['category']['ls']['num'], 1);
  104. } else {
  105. $incomeList['debtClear']['amount'] = bcadd($incomeList['debtClear']['amount'], $debtPrice, 2);
  106. $incomeList['debtClear']['num'] = bcadd($incomeList['debtClear']['num'], 1);
  107. $incomeList['debtClear']['category']['ls']['amount'] = bcadd($incomeList['debtClear']['category']['ls']['amount'], $debtPrice, 2);
  108. $incomeList['debtClear']['category']['ls']['num'] = bcadd($incomeList['debtClear']['category']['ls']['num'], 1);
  109. }
  110. }
  111. //付订金的情况!!
  112. $currentAmount = $remainDebtPrice > 0 ? bcsub($mainPay, $remainDebtPrice, 2) : $mainPay;
  113. //使用非在线支付
  114. switch ($payWay) {
  115. case dict::getDict('payWay', 'wxPay'):
  116. //员工微信总共收了多少笔多少钱
  117. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $currentAmount, 2);
  118. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  119. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  120. $incomeList['kfWx']['category']['ls']['amount'] = bcadd($incomeList['kfWx']['category']['ls']['amount'], $currentAmount, 2);
  121. $incomeList['kfWx']['category']['ls']['num'] = bcadd($incomeList['kfWx']['category']['ls']['num'], 1);
  122. //客1 客2 客3各收了多少钱
  123. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  124. $incomeList['kfWx']['class'][$getStaffId]['amount'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $currentAmount, 2);
  125. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  126. }
  127. //每个客服收的明细
  128. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls'])) {
  129. $incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['amount'], $actPrice, 2));
  130. $incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['num'], 1);
  131. }
  132. break;
  133. case dict::getDict('payWay', 'alipay'):
  134. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $currentAmount, 2);
  135. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  136. $incomeList['aliPay']['category']['ls']['amount'] = bcadd($incomeList['aliPay']['category']['ls']['amount'], $currentAmount, 2);
  137. $incomeList['aliPay']['category']['ls']['num'] = bcadd($incomeList['aliPay']['category']['ls']['num'], 1);
  138. break;
  139. case dict::getDict('payWay', 'cash'):
  140. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $currentAmount, 2);
  141. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  142. $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $currentAmount, 2);
  143. $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
  144. break;
  145. case dict::getDict('payWay', 'bankCard'):
  146. $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $currentAmount, 2);
  147. $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  148. $incomeList['bankCard']['category']['ls']['amount'] = bcadd($incomeList['bankCard']['category']['ls']['amount'], $currentAmount, 2);
  149. $incomeList['bankCard']['category']['ls']['num'] = bcadd($incomeList['bankCard']['category']['ls']['num'], 1);
  150. break;
  151. case dict::getDict('payWay', 'unknown'):
  152. $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $currentAmount, 2);
  153. $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  154. $incomeList['other']['category']['ls']['amount'] = bcadd($incomeList['other']['category']['ls']['amount'], $currentAmount, 2);
  155. $incomeList['other']['category']['ls']['num'] = bcadd($incomeList['other']['category']['ls']['num'], 1);
  156. break;
  157. default:
  158. }
  159. }
  160. }
  161. }
  162. $total = 0;
  163. foreach ($incomeList as $i) {
  164. $current = $i['amount'] ?? 0;
  165. $total = bcadd($current, $total, 2);
  166. }
  167. echo '<br />零售收入:' . $total . ' ' . $an . ' <br />';
  168. print_r($incomeList);
  169. die;
  170. }
  171. //即时配送
  172. public function actionGetBindAccount()
  173. {
  174. $merchant = WxOpenClass::getGhsWxInfo();
  175. $isOpen = 2;
  176. $r = miniUtil::getBindAccount($merchant, $isOpen);
  177. dd($r);
  178. }
  179. public function actionDada()
  180. {
  181. //https://github.com/wanDoubleMing/dada_openapi_php
  182. //初始化一个配置文件
  183. $dada = Yii::getAlias("@vendor/dada/");
  184. require_once $dada . 'api/addOrderApi.php';
  185. require_once $dada . 'client/dadaRequestClient.php';
  186. require_once $dada . 'client/dadaResponse.php';
  187. require_once $dada . 'config/config.php';
  188. require_once $dada . 'model/orderModel.php';
  189. // isOnline 判断是否是测试环境,会有不同的域名等
  190. $isOnline = false;
  191. //商户id
  192. $sourceId = 73753;
  193. $shopNo = 11047059;
  194. // 初始化一个config
  195. $config = new \Config($sourceId, $isOnline);
  196. //3.domain文件新建一个model,并初始化
  197. $orderModel = new \OrderModel();
  198. $orderModel->setShopNo($shopNo);
  199. $orderModel->setOriginId('2020043017180001');
  200. $orderModel->setCityCode('021');
  201. $orderModel->setCargoPrice(10);
  202. $orderModel->setIsPrepay(0);
  203. $orderModel->setReceiverName('测试达达');
  204. $orderModel->setReceiverAddress('上海市崇明岛');
  205. $orderModel->setReceiverLat(31.63);
  206. $orderModel->setReceiverLng(121.41);
  207. $orderModel->setReceiverPhone('15280215347');
  208. $orderModel->setCallback('https://api.saas.huaml.com/express/callback');
  209. // api主要有2个参数,一个是url, 一个是业务参数
  210. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  211. //5.初始化客户端,并调用rpc
  212. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  213. $resp = $dada_client->makeRequest();
  214. echo json_encode($resp);
  215. }
  216. public function actionRabbit()
  217. {
  218. $orderId = 214752;
  219. $order = OrderService::getById($orderId);
  220. $sjId = $order['sjId'];
  221. $openMerchant = WxOpenService::getWxInfo();
  222. $merchant = MerchantService::getMerchantById($sjId);
  223. $shopId = $merchant['defaultShopId'];
  224. $params = ['sourceType' => $order['sourceType'], 'miniAppId' => $openMerchant['miniAppId'], 'orderId' => $orderId];
  225. $type = 'income';
  226. InformAdminService::addInform($shopId, $type, $params);
  227. }
  228. //添加优惠券 ssh 2020.5.5
  229. public function actionAddCoupon()
  230. {
  231. $merchant = MerchantService::getMerchantById(12358);
  232. $user = UserService::getById(12543444);
  233. UserService::focus($user, $merchant);
  234. }
  235. public function actionGetUnionId()
  236. {
  237. $merchant = MerchantService::getMerchantById(12358);
  238. $extend = MerchantExtendService::getBySjId(12358);
  239. $mcId = $extend['wxPayMerchantId'];
  240. $orderId = '200512145420123581254345688252';
  241. miniUtil::getPaidUnionId($merchant, 'o-hXO4qOzIVbUNVucoFzEiArOz5k', $mcId, $orderId, 0);
  242. }
  243. public function actionCalc()
  244. {
  245. $dis = mapUtil::calculateDistance('116.308479', '39.983171', '116.328479', '39.973171');
  246. echo $dis;
  247. }
  248. }