Supply.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\mainapp\controller;
  3. use think\facade\Session;
  4. use app\mainapp\BaseController;
  5. use app\common\model\User as UserModel;
  6. use app\common\model\Supply as SupplyModel;
  7. use app\common\model\Param as ParamModel;
  8. use app\common\model\Worker as WorkerModel;
  9. use app\common\model\WorkerLog as WorkerLogModel;
  10. use app\common\model\UserIntegral as UserIntegralModel;
  11. use echowx\WxProgram;
  12. class Supply extends BaseController
  13. {
  14. // 供人总列表
  15. public function listSupply()
  16. {
  17. $ppage = input('ppage/d', 1);
  18. $psize = input('psize/d', 20);
  19. $map = array();
  20. $map[] = ['createtime','<=',time()];
  21. $map[] = ['status','in','3,4'];
  22. $searchval = input('searchval/s', "");
  23. if (!empty($searchval)){
  24. $map[] =['descity', 'like', '%'.$searchval.'%'];
  25. }
  26. $orderby = array('status'=>'asc', 'updatetime'=>'desc', 'id'=>'desc');
  27. $plist = SupplyModel::with(['worker'])->where($map)->order($orderby)->page($ppage)->limit($psize)->select();
  28. foreach($plist as $key=>$row){
  29. $plist[$key]->updatetime_text = tranTime(strtotime($row->updatetime));
  30. }
  31. page_result(0, "", array(
  32. 'plist' => $plist,
  33. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more'
  34. ));
  35. }
  36. // 供人详情
  37. public function getSupply()
  38. {
  39. $supplyid = input('supplyid/d', 0);
  40. $supply = SupplyModel::with(['worker'])->where('status','in','3,4')->where('id','=',$supplyid)->findOrEmpty();
  41. if ($supply->isEmpty()){
  42. page_result(1, "供人信息不存在。");
  43. }
  44. $supply->updatetime_text = tranTime(strtotime($supply->updatetime));
  45. $supply->inc('volume', 1)->update();
  46. $supplylist = SupplyModel::with(['worker'])->where(['status'=>3,'workerid'=>$supply->workerid])->where('createtime','<=',time())->order(['updatetime'=>'desc','createtime'=>'desc','id'=>'desc'])->limit(5)->select();
  47. foreach($supplylist as $key=>$row){
  48. $supplylist[$key]->updatetime_text = tranTime(strtotime($row->updatetime));
  49. }
  50. $userid = input('userid/d', 0);
  51. $workerlog = WorkerLogModel::where(['workerid'=>$supply->workerid,'userid'=>$userid])->whereDay('createtime')->findOrEmpty();
  52. if ($workerlog->isEmpty()){
  53. WorkerLogModel::create([
  54. 'workerid' => $supply->workerid,
  55. 'userid' => $userid,
  56. 'ltotal' => 1,
  57. 'createtime' => date("Y-m-d")
  58. ]);
  59. }else{
  60. $workerlog->inc('ltotal', 1)->update();
  61. }
  62. $iscantele = in_array($userid, $supply->telearr);
  63. $param = ParamModel::where(1)->findOrEmpty();
  64. page_result(0, "", array(
  65. 'param' => $param,
  66. 'supply' => $supply,
  67. 'iscantele' => $iscantele,
  68. 'supplylist' => $supplylist
  69. ));
  70. }
  71. public function teleSupply()
  72. {
  73. $supplyid = input('supplyid/d', 0);
  74. $supply = SupplyModel::findOrEmpty($supplyid);
  75. if ($supply->isEmpty()){
  76. page_result(1, "订单信息不存在");
  77. }
  78. $userid = input('userid/d', 0);
  79. if (in_array($userid, $supply->telearr)){
  80. page_result(0, "", array(
  81. 'iscantele' => true
  82. ));
  83. }
  84. $user = UserModel::where(1)->findOrEmpty($userid);
  85. $param = ParamModel::where(1)->findOrEmpty();
  86. if ($user->integral < $param->telsupply){
  87. page_result(1, "拨打咨询电话会扣除".$param->telsupply."积分,你当前积分不足。");
  88. }
  89. $intdata = array(
  90. 'userid' => $userid,
  91. 'title' => "电话咨询供人信息扣除",
  92. 'intvalue' => 0 - $param->telsupply,
  93. 'intmoney' => 0.00,
  94. 'onlycontent' => "",
  95. 'remark' => "男性".$supply->mnumber."人,女性".$supply->wnumber."人【".$supply->agegroup."】",
  96. 'itype' => 6,
  97. 'status' => 2,
  98. 'createtime' => date("Y-m-d H:i:s"),
  99. 'yeartime' => date("Y"),
  100. 'monthtime' => date("Ym")
  101. );
  102. UserIntegralModel::create($intdata);
  103. $integral = intval($user->integral) - intval($param->addsupply);
  104. $user->save([
  105. 'integral' => $integral
  106. ]);
  107. $telearr = $supply->telearr;
  108. $telearr[] = $userid;
  109. $supply->save([
  110. 'telearr' => $telearr
  111. ]);
  112. page_result(0, "", array(
  113. 'iscantele' => true
  114. ));
  115. }
  116. }