HoldersBonus.Class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. /**
  3. * 分红
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Controller\Holders;
  10. use JinDouYun\Dao\Customer\DCustomer;
  11. use JinDouYun\Dao\Customer\DMemberBalanceDetail;
  12. use JinDouYun\Dao\Order\DOrder;
  13. use JinDouYun\Model\Enterprise\MEnterprise;
  14. use JinDouYun\Model\Holders\MHoldersBonus;
  15. use JinDouYun\Model\System\MBasicSetup;
  16. use Mall\Framework\Core\ErrorCode;
  17. use Mall\Framework\Core\ResultWrapper;
  18. use Mall\Framework\Core\StatusCode;
  19. use JinDouYun\Cache\ShopCache;
  20. use JinDouYun\Controller\BaseController;
  21. use JinDouYun\Cache\TempSaveCache;
  22. class HoldersBonus extends BaseController
  23. {
  24. private $obj;
  25. private $objShopCache;
  26. private $objTempSaveCache;
  27. public function __construct($isCheckAcl = true, $isMustLogin = true)
  28. {
  29. parent::__construct($isCheckAcl, $isMustLogin);
  30. $this->obj = new MHoldersBonus($this->onlineEnterpriseId, $this->onlineUserId);
  31. $this->objShopCache = new ShopCache();
  32. $this->objTempSaveCache = new TempSaveCache();
  33. }
  34. /**
  35. * 添加和编辑商铺管理公共字段处理方法
  36. *
  37. * @return array
  38. */
  39. public function commonFieldFilter(){
  40. $params = $this->request->getRawJson();
  41. if( empty($params) ){
  42. $this->sendOutput('参数为空', ErrorCode::$paramError );
  43. }
  44. $shopData = [
  45. 'name' => isset($params['name']) ? $params['name'] : '',
  46. 'price' => isset($params['price']) ? $params['price'] : '',
  47. 'ot_price' => isset($params['ot_price']) ? $params['ot_price'] : '',
  48. 'image' => isset($params['image']) ? $params['image'] : '',
  49. ];
  50. //非暂存则验空
  51. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  52. foreach($shopData as $key => $value){
  53. if(empty($value) && $value !== 0){
  54. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  55. }
  56. }
  57. }
  58. $shopData['info']= isset($params['info']) ? $params['info'] : false;
  59. $shopData['introduce']= isset($params['introduce']) ? $params['introduce'] : false;
  60. $shopData['status']= isset($params['status']) ? $params['status'] : 1;
  61. return $shopData;
  62. }
  63. /**
  64. * 列表
  65. */
  66. public function list()
  67. {
  68. $params = $this->request->getRawJson();
  69. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  70. $selectParams['limit'] = $pageParams['limit'];
  71. $selectParams['offset'] = $pageParams['offset'];
  72. //uid
  73. if(isset($params['name']) && !empty($params['name'])){
  74. $selectParams['name'] = $params['name'];
  75. }
  76. if(isset($params['start_time']) && !empty($params['start_time'])){
  77. $selectParams['start_time'] = $params['start_time'];
  78. }
  79. if(isset($params['end_time']) && !empty($params['end_time'])){
  80. $selectParams['end_time'] = $params['end_time'];
  81. }
  82. if(isset($params['type']) && !empty($params['type'])){
  83. $selectParams['type'] = $params['type'];
  84. }
  85. $result = $this->obj->list($selectParams);
  86. if ($result->isSuccess()) {
  87. $returnData = $result->getData();
  88. $pageData = [
  89. 'pageIndex' => $params['page'],
  90. 'pageSize' => $params['pageSize'],
  91. 'pageTotal' => $returnData['total'],
  92. ];
  93. parent::sendOutput($returnData['data'], 0, $pageData);
  94. } else {
  95. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  96. }
  97. }
  98. /**
  99. * 添加
  100. * @throws \Exception
  101. */
  102. public function add()
  103. {
  104. $addStaffData = $this->commonFieldFilter();
  105. // $addStaffData['shop_id'] = $this->shopId;
  106. $addStaffData['enterprise_id'] = $this->onlineEnterpriseId;
  107. $result = $this->obj->insert($addStaffData);
  108. if ($result->isSuccess()) {
  109. parent::sendOutput($result->getData());
  110. } else {
  111. parent::sendOutput($result->getData(), $result->getErrorCode());
  112. }
  113. }
  114. /**
  115. * 详情
  116. * @return void
  117. */
  118. public function details()
  119. {
  120. $where = [];
  121. $id = $this->request->param('id');
  122. if(!empty($id)){
  123. $where['id'] = $id;
  124. }
  125. $result = $this->obj->details($where);
  126. if ($result->isSuccess()) {
  127. parent::sendOutput($result->getData());
  128. } else {
  129. parent::sendOutput($result->getData(), $result->getErrorCode());
  130. }
  131. }
  132. /**
  133. * 修改
  134. * @return void
  135. */
  136. public function update()
  137. {
  138. $id['id'] = $this->request->param('id');
  139. if (empty($id['id'])) {
  140. $this->sendOutput('参数为空', ErrorCode::$paramError);
  141. }
  142. $params = $this->commonFieldFilter();
  143. $result = $this->obj->update($params, $id);
  144. if ($result->isSuccess()) {
  145. parent::sendOutput($result->getData());
  146. } else {
  147. parent::sendOutput($result->getData(), $result->getErrorCode());
  148. }
  149. }
  150. public function delete()
  151. {
  152. $id['id'] = $this->request->param('id');
  153. if (empty($id['id'])) {
  154. $this->sendOutput('参数为空', ErrorCode::$paramError);
  155. }
  156. $result = $this->obj->delete($id);
  157. if ($result->isSuccess()) {
  158. parent::sendOutput($result->getData());
  159. } else {
  160. parent::sendOutput($result->getData(), $result->getErrorCode());
  161. }
  162. }
  163. public function bonus()
  164. {
  165. $Menterprise = new MEnterprise();
  166. $en = $Menterprise->list([])->getData();
  167. foreach ($en['data'] as $item)
  168. {
  169. $Mbasi = new MBasicSetup($item['id']);
  170. $basi = $Mbasi->getBasicSetup()->getData();
  171. $Mholders = new \JinDouYun\Model\Holders\Holders();
  172. $objDOrder = new DOrder('default');
  173. $objDOrder->setTable('qianniao_order_'.$item['id'].'_1');
  174. $objCustomer = new DCustomer('default');
  175. $objCustomer->setTable('qianniao_customer_'.$item['id']);
  176. $objMenber = new DMemberBalanceDetail('default');
  177. $objMenber->setTable('qianniao_member_balance_detail_'.$item['id']);
  178. if ($basi){
  179. $holders_original = $Mholders->getSum($item['id']);//所有股份
  180. $order = $objDOrder->select(['payStatus' => 5,'returnStatus' => 0], 'sum(payAmount) as payAmount');
  181. if ($holders_original['shares'] > 0 || $holders_original['dends'] > 0 and $order){
  182. $original_bonus = $basi['basicData']['original_bonus'] / 100;//原始股份分红比列
  183. $bonus = $basi['basicData']['bonus'] / 100;//分红股份分红比列
  184. if ($holders_original['shares'] > 0){
  185. $originalPrice = round($order[0]['payAmount'] * $original_bonus,3); // 原始股分红总金额
  186. $originalPriceOne = round($order[0]['payAmount'] * $original_bonus/$holders_original['shares'], 3); // 原始股分红单份金额
  187. }
  188. if ($holders_original['dends'] > 0){
  189. $bonusPrice = round($order[0]['payAmount'] * $bonus,2); // 分红股分红总金额
  190. $bonusPriceOne = round($order[0]['payAmount'] * $bonus/$holders_original['dends'], 3); // 分红股分红单份金额
  191. }
  192. $user = $Mholders->Lst(['limit' => 0])->getData();
  193. foreach ($user['data'] as $vo)
  194. {
  195. if ($originalPriceOne > 0 and $vo['shares'] > 0){
  196. $customer = $objCustomer->get(['id' => $vo['us_id']]);
  197. $number = round($originalPriceOne * $vo['shares'], 3);//原始股份分红
  198. $before = $customer['memberBalance'];//变动前
  199. $after = $number + $before;//变动后
  200. $bounsInsert = [
  201. 'hol_id' => $vo['id'],
  202. 'en_id' => $item['id'],
  203. 'mark' => '原始股份分红',
  204. 'type' => 1,
  205. 'number' => $number,
  206. 'before' => $before,
  207. 'after' => $after,
  208. 'total' => $originalPrice,
  209. 'total_shares' => $holders_original['shares'],
  210. 'shares' => $vo['shares']
  211. ];
  212. $memberInsert = [
  213. 'customerId' => $customer['id'],
  214. 'userCenterId' => $customer['userCenterId'],
  215. 'type' => 5,
  216. 'purpose' => '原始股份分红',
  217. 'money' => $number,
  218. 'afterMoney' => $after,
  219. 'beforeMoney' => $before,
  220. 'remark' => '原始股份分红',
  221. 'createTime' => time(),
  222. 'updateTime' => time(),
  223. ];
  224. $this->obj->insert($bounsInsert);
  225. $objMenber->insert($memberInsert);
  226. $objCustomer->update(['memberBalance' => $after], $vo['us_id']);
  227. }
  228. if ($bonusPriceOne > 0 and $vo['dends'] > 0){
  229. $customer = $objCustomer->get(['id' => $vo['us_id']]);
  230. $number = round($bonusPriceOne * $vo['dends'], 3);//原始股份分红
  231. $before = $customer['memberBalance'];//变动前
  232. $after = $number + $before;//变动后
  233. $bounsInsert = [
  234. 'hol_id' => $vo['id'],
  235. 'en_id' => $item['id'],
  236. 'mark' => '分红股份分红',
  237. 'type' => 2,
  238. 'number' => $number,
  239. 'before' => $before,
  240. 'after' => $after,
  241. 'total' => $bonusPrice,
  242. 'total_shares' => $holders_original['dends'],
  243. 'shares' => $vo['shares']
  244. ];
  245. $memberInsert = [
  246. 'customerId' => $customer['id'],
  247. 'userCenterId' => $customer['userCenterId'],
  248. 'type' => 5,
  249. 'purpose' => '分红股份分红',
  250. 'money' => $number,
  251. 'afterMoney' => $after,
  252. 'beforeMoney' => $before,
  253. 'remark' => '分红股份分红',
  254. 'createTime' => time(),
  255. 'updateTime' => time(),
  256. ];
  257. $this->obj->insert($bounsInsert);
  258. $objMenber->insert($memberInsert);
  259. $objCustomer->update(['memberBalance' => $after], $vo['us_id']);
  260. }
  261. }
  262. echo '企业'.$item['id'].'发放成功';
  263. }
  264. }
  265. }
  266. }
  267. }