Consult.php 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //竞价单(咨询单)
  10. class Consult extends Base
  11. {
  12. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble =\think\facade\Config::get("noble");
  17. }
  18. public function conlist(){
  19. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  20. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  21. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  22. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  23. if ($infoNo !== "") {
  24. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  25. }
  26. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  27. if ($salesman !== "") {
  28. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  29. $where[]= ["b.salesman",'like',"%$salesman%"];
  30. }
  31. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  32. if ($cpName !== "") {
  33. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  34. $where[]= ["a.good_Name",'like',"%$cpName%"];
  35. }
  36. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  37. if ($khNo !== "") {
  38. // $where['khNo'] = $khNo;
  39. $where[]= ["b.khNo",'like',"%$khNo%"];
  40. }
  41. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  42. if ($companyNo !== "") {
  43. // $where['khNo'] = $khNo;
  44. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  45. }
  46. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  47. if ($start !="") {
  48. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  49. $where[]= ["a.addtime",'>=',$start];
  50. }
  51. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  52. if($end !=""){
  53. $where[]= ["a.addtime",'<=',$end];
  54. }
  55. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  56. if ($status !== "") {
  57. $where[]= ["a.status",'=',$status];
  58. }
  59. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  60. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  61. // $role=$this->checkRole();
  62. // if(!empty($role['write'])){
  63. // $where[]=["b.createrid","in",$role['write']];
  64. // }
  65. // $role = $this->checkDataShare();
  66. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["b.createrid", "in", $role[DataGroupModel::$type_全部]];
  67. $role = $this->checkDataShare();
  68. $hand = resign_hand_user($this->uid,0);
  69. if (!empty($role[DataGroupModel::$type_全部])) {
  70. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  71. $where[] = ['b.createrid', 'in',$arr];
  72. }
  73. // if(!empty($role['platform']) ){
  74. // $where[]=["b.platform_code","in",$role['platform']];
  75. // }
  76. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  77. ->count();
  78. $total = ceil($count / $size);
  79. $page = $page >= $total ? $total : $page;
  80. $list = Db::name('consult_info')
  81. ->alias("a")
  82. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  83. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  84. ->where($where)
  85. ->page($page, $size)
  86. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  87. ->order("a.id desc")
  88. ->cursor();
  89. $data=[];
  90. foreach ($list as $value){
  91. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  92. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  93. true):[];
  94. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  95. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  96. $value['khname']="";
  97. if($value['khNo']!==""){
  98. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  99. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  100. }
  101. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  102. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  103. //是否具有编辑权限
  104. $value['is_allow_update'] = 0;
  105. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  106. $data[]=$value;
  107. }
  108. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  109. }
  110. public function info(){
  111. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  112. if($id==""){
  113. return error_show(1002,"咨询单编号不能为空");
  114. }
  115. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  116. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  117. $fo['can']=$in;
  118. if(empty($fo)){
  119. return error_show(1002,"未找到咨询单编号");
  120. }else{
  121. return app_show(0,"获取成功",$fo);
  122. }
  123. }
  124. public function del(){
  125. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  126. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  127. if($de==false){
  128. return error_show(1002,'咨询单信息未找到');
  129. }
  130. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  131. if($dell){
  132. return error_show(0,"删除成功");
  133. }else
  134. return error_show(1002,"删除失败");
  135. }
  136. public function create(){
  137. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  138. if($is_project===""){
  139. return error_show(1002,"参数is_project不能为空");
  140. }
  141. if($is_project==1){
  142. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  143. if($projectNo===""){
  144. return error_show(1002,"参数projectNo不能为空");
  145. }
  146. }
  147. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  148. if($khNo===""){
  149. return error_show(1002,"参数khNo不能为空");
  150. }
  151. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  152. if($companyNo===""){
  153. return error_show(1002,"参数companyNo不能为空");
  154. }
  155. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  156. if($endtime===""){
  157. return error_show(1002,"参数endtime不能为空");
  158. }
  159. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  160. "";
  161. if($platform_code===""){
  162. return error_show(1002,"参数platform_code不能为空");
  163. }
  164. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  165. if($ladder==""){
  166. return error_show(1005,"参数ladder不能为空");
  167. }
  168. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  169. if($token==''){
  170. return error_show(105,"参数token不能为空");
  171. }
  172. $pay_id = isset($this->post['pay_id']) && $this->post['pay_id'] !== "" ? intval($this->post['pay_id']) : "0";
  173. if($pay_id!=0){
  174. $payinfo =Db::name("pay")->where("id",$pay_id)->findOrEmpty();
  175. if(empty($payinfo)) return error_show(1004, "支付渠道信息未找到");
  176. if($payinfo['status']!=1)return error_show(1004, "支付渠道已禁用");
  177. $supplierArr =Db::name("pay_rate")->where(["pay_id"=>$pay_id,"status"=>1,"is_del"=>0])->column("companyNo");
  178. if(in_array($companyNo,$supplierArr)) return error_show(1004, "支付渠道含有该业务公司,支付渠道无法使用!");
  179. }
  180. $user =GetUserInfo($token);
  181. if(empty($user)||$user['code']!=0){
  182. return error_show(102,"用户数据不存在");
  183. }
  184. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  185. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  186. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  187. $zxNo=makeNo("ZX");
  188. Db::startTrans();
  189. try{
  190. $data=[
  191. "zxNo"=>$zxNo,
  192. "createrid"=>$createrid,
  193. "creater"=>$creater,
  194. "is_project"=>$is_project,
  195. "projectNo"=>isset($projectNo) ? $projectNo:"",
  196. "khNo"=>$khNo,
  197. "companyNo"=>$companyNo,
  198. "endtime"=>$endtime,
  199. "salesman"=>$creater,
  200. "platform_code"=>$platform_code,
  201. "saleid"=>$createrid,
  202. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  203. "pay_id"=>$pay_id,
  204. "status"=>0,
  205. "is_del"=>0,
  206. "addtime"=>date("Y-m-d H:i:s"),
  207. "updatetime"=>date("Y-m-d H:i:s"),
  208. ];
  209. $zx = Db::name("consult_order")->insert($data);
  210. if($zx){
  211. //判断是否是项目,且该项目是否存在台账记录中
  212. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  213. foreach ($ladder as $value){
  214. $infoNo=makeNo("IF");
  215. $specinfo=[];
  216. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  217. foreach ($value["specinfo"] as $v){
  218. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  219. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  220. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  221. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  222. $specinfo[]=$v;
  223. }
  224. }
  225. $info=[
  226. "infoNo"=>$infoNo,
  227. "zxNo"=>$zxNo,
  228. "spuCode"=>"",
  229. "good_name"=>$value['good_name'],
  230. "good_img"=>$value['good_img'],
  231. "cat_id"=>$value['cat_id'],
  232. "unit"=>$value['unit'],
  233. "brand_id"=>$value['brand_id'],
  234. "arrival_time"=>$value['arrival_time'],
  235. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  236. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  237. "is_addrs"=>$value['is_addrs'],
  238. "is_custom"=>$value['is_custom'],
  239. "metal_id"=>$value['metal_id'],
  240. "config"=>isset($value['config'])?$value['config']:"",
  241. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  242. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  243. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  244. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  245. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  246. "budget_price"=>$value['budget_price'],
  247. "num"=>$value['num'],
  248. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  249. "use_desc"=>$value['use_desc'],
  250. "remark"=>$value['remark'],
  251. "status"=>1,
  252. "is_del"=>0,
  253. "addtime"=>date("Y-m-d H:i:s"),
  254. "updatetime"=>date("Y-m-d H:i:s"),
  255. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  256. ];
  257. $up = Db::name("consult_info")->insertGetId($info);
  258. if(!$up){
  259. Db::rollback();
  260. return error_show(1004,'添加失败');
  261. }else{
  262. //修改状态
  263. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  264. "order_code" => $infoNo,//咨询单详情编号
  265. "status" => 1,//这里的status是之前的值
  266. "action_remark" => '',//备注
  267. "action_type" => "create"//新建create,编辑edit,更改状态status
  268. ], "ZXD", 1, $info);
  269. //竞价单不走流程,不推待办已办
  270. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  271. // "order_type" => 'ZXD',
  272. // "order_code" => $infoNo,//咨询单详情编号
  273. // "order_id" => $up,
  274. // "order_status" => 1,
  275. // 'before_status'=>0
  276. // ]);
  277. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  278. if (isset($stand_exists)) {
  279. Db::name('standing_book')
  280. ->where('id', $stand_exists['id'])
  281. ->update([
  282. 'infoNo' => $infoNo,
  283. 'updatetime' => date('Y-m-d H:i:s')
  284. ]);
  285. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  286. } else {
  287. //添加台账信息
  288. Db::name('standing_book')
  289. ->insert([
  290. 'standBookNo' => makeNo("IO"),
  291. 'projectNo' => isset($projectNo) ? $projectNo : '',
  292. 'infoNo' => $infoNo,
  293. 'companyNo' => $companyNo,
  294. 'customer_code' => $khNo,
  295. 'addtime' => date('Y-m-d H:i:s'),
  296. 'updatetime' => date('Y-m-d H:i:s')
  297. ]);
  298. }
  299. }
  300. }
  301. Db::commit();
  302. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  303. }else{
  304. Db::rollback();
  305. return error_show(1004,"新建失败");
  306. }
  307. }catch (\Exception $e){
  308. Db::rollback();
  309. return error_show(1003,$e->getMessage());
  310. }
  311. }
  312. /**
  313. * @return \think\response\Json|void
  314. * @throws \think\db\exception\DataNotFoundException
  315. * @throws \think\db\exception\DbException
  316. * @throws \think\db\exception\ModelNotFoundException
  317. */
  318. public function zxinfo(){
  319. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  320. if($infoNo==""){
  321. return error_show(1004,"参数infoNo不能为空");
  322. }
  323. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  324. if($zxinfo==false){
  325. return error_show(1004,"未找到信息数据");
  326. }
  327. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  328. if($zxorder==false){
  329. return error_show(1004,"未找到咨询信息数据");
  330. }
  331. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  332. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  333. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  334. $zxinfo['khname']="";
  335. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  336. $zxinfo['khNo']="";
  337. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  338. $zxinfo['brand']="";
  339. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  340. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  341. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  342. $zxinfo['company']="";
  343. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  344. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  345. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  346. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  347. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  348. $zxinfo['project_name']="";
  349. $zxinfo['budget_total']="";
  350. $zxinfo['departinfo']=[];
  351. $zxinfo['unit_name']="";
  352. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  353. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  354. $zxinfo['pay_name'] = $zxorder['pay_id']==0?"":Db::name("pay")->where("id",$zxorder['pay_id'])->value("pay_name",'');
  355. if($zxorder['khNo']!==""){
  356. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  357. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  358. $zxinfo['khNo']= $zxorder['khNo'];
  359. }
  360. if($zxinfo['unit']!==""){
  361. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  362. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  363. }
  364. if($zxinfo['brand_id']!==""){
  365. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  366. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  367. }
  368. if($zxorder['companyNo']!==""){
  369. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  370. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  371. }
  372. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  373. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  374. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  375. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  376. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  377. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  378. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  379. }
  380. if($zxorder['depart']>0){
  381. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  382. }
  383. if($zxorder['platform_code']>0){
  384. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  385. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  386. }
  387. return app_show(0,"获取成功",$zxinfo);
  388. }
  389. public function zxedit(){
  390. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  391. if($infoNo==""){
  392. return error_show(1004,"参数infoNo不能为空");
  393. }
  394. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  395. if($zxinfo==false){
  396. return error_show(1004,"未找到信息数据");
  397. }
  398. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  399. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  400. if($good_name==""){
  401. return error_show(1003,"参数good_name不能为空");
  402. }
  403. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  404. if($good_img==""){
  405. return error_show(1003,"参数good_img不能为空");
  406. }
  407. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  408. if($cat_id==""){
  409. return error_show(1003,"参数cat_id不能为空");
  410. }
  411. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  412. if($unit==""){
  413. return error_show(1003,"参数unit不能为空");
  414. }
  415. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  416. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  417. if($arrival_time==""){
  418. return error_show(1003,"参数arrival_time不能为空");
  419. }
  420. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  421. if($specin==""){
  422. return error_show(1003,"参数specinfo不能为空");
  423. }
  424. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  425. // if($cost_desc==""){
  426. // return error_show(1003,"参数cost_desc不能为空");
  427. // }
  428. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  429. if($is_addrs===""){
  430. return error_show(1003,"参数is_addrs不能为空");
  431. }
  432. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  433. if($is_custom===""){
  434. return error_show(1003,"参数is_custom不能为空");
  435. }
  436. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  437. if($metal_id===""){
  438. return error_show(1003,"参数metal_id不能为空");
  439. }
  440. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  441. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  442. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  443. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  444. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  445. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  446. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  447. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  448. if($num===""){
  449. return error_show(1003,"参数num不能为空");
  450. }
  451. if($budget_price===""){
  452. return error_show(1003,"参数budget_price不能为空");
  453. }
  454. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  455. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  456. if($use_desc==""){
  457. return error_show(1003,"参数use_desc不能为空");
  458. }
  459. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  460. if($remark==""){
  461. return error_show(1003,"参数remark不能为空");
  462. }
  463. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  464. if($endtime==""){
  465. return error_show(1003,"参数endtime不能为空");
  466. }
  467. if($metal_id!=0){
  468. if($config==""){
  469. return error_show(1003,"参数config不能为空");
  470. }
  471. if($other_config==""){
  472. return error_show(1003,"参数other_config不能为空");
  473. }
  474. if($specs_weight===""){
  475. return error_show(1003,"参数specs_weight不能为空");
  476. }
  477. if($gold_price===""){
  478. return error_show(1003,"参数gold_price不能为空");
  479. }
  480. }
  481. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  482. if($token==''){
  483. return error_show(102,"参数token不能为空");
  484. }
  485. $user =GetUserInfo($token);
  486. if(empty($user)||$user['code']!=0){
  487. return error_show(105,"用户数据不存在");
  488. }
  489. $specinfo=[];
  490. foreach ($specin as $v){
  491. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  492. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  493. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  494. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  495. $specinfo[]=$v;
  496. }
  497. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  498. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  499. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  500. Db::startTrans();
  501. try{
  502. $innew =makeNo("IF");
  503. $info=[
  504. "infoNo"=>$innew,
  505. "zxNo"=>$zxinfo['zxNo'],
  506. "spuCode"=>"",
  507. "good_name"=>$good_name,
  508. "good_img"=>$good_img,
  509. "cat_id"=>$cat_id,
  510. "unit"=>$unit,
  511. "brand_id"=>$brand_id,
  512. "arrival_time"=>$arrival_time,
  513. "specinfo"=>json_encode($specinfo),
  514. // "color"=>$color,
  515. // "material"=>$material,
  516. "cost_desc"=>$cost_desc,
  517. "is_addrs"=>$is_addrs,
  518. "is_custom"=>$is_custom,
  519. "metal_id"=>$metal_id,
  520. "config"=>$config,
  521. "other_config"=>$other_config,
  522. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  523. "gold_price"=>$gold_price===""? 0 : $gold_price,
  524. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  525. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  526. "budget_price"=>$budget_price,
  527. "num"=>$num,
  528. "pgNo"=>$pgNo,
  529. "use_desc"=>$use_desc,
  530. "remark"=>$remark,
  531. "bargain_num"=>$zxinfo['bargain_num']+1,
  532. "status"=>1,
  533. "is_del"=>0,
  534. "addtime"=>date("Y-m-d H:i:s"),
  535. "updatetime"=>date("Y-m-d H:i:s"),
  536. 'bargain_status'=>1,
  537. 'enclosure_file'=>$enclosure_file
  538. ];
  539. $up = Db::name("consult_info")->insert($info);
  540. if($up){
  541. //操作记录
  542. ActionLog::logAdd($this->post['token'], [
  543. "order_code" => $innew,//咨询单详情编号
  544. "status" => 1,//这里的status是之前的值
  545. "action_remark" => '',//备注
  546. "action_type" => "edit"//新建create,编辑edit,更改状态status
  547. ], "ZXD", 1, $this->post);
  548. // ProcessOrder::AddProcess($this->post['token'], [
  549. // "order_type" => 'ZXD',
  550. // "order_code" => $innew,//咨询单详情编号
  551. // "order_id" => 0,
  552. // "order_status" => 1
  553. // ]);
  554. if (!empty($bidlist)){
  555. foreach ($bidlist as $value){
  556. unset($value['id']);
  557. $value['infoNo']=$innew;
  558. $value['bidNo']=makeNo("BD");
  559. $value['spuCode']=makeNo("SKU");
  560. $value['status'] =0;
  561. $value['updatetime'] =date("Y-m-d H:i:s");
  562. $in = Db::name("consult_bids")->insert($value);
  563. if($in==false){
  564. Db::rollback();
  565. return error_show(1004,"反馈商品新建失败");
  566. }
  567. ActionLog::logAdd($this->post['token'], [
  568. "order_code" => $innew,//咨询单详情编号
  569. "status" => 1,//这里的status是之前的值
  570. "action_remark" => '',//备注
  571. "action_type" => "edit"//新建create,编辑edit,更改状态status
  572. ], "FKD", 1, $this->post);
  573. }
  574. }
  575. $zxinfo["bargain_status"] =1;
  576. $zxinfo["status"] =6;
  577. $zxinfo["bargain_code"] =$innew;
  578. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  579. $bar=Db::name("consult_info")->save($zxinfo);
  580. if($bar==false){
  581. Db::rollback();
  582. return error_show(1004,"反馈商品更新失败");
  583. }else{
  584. //修改状态,添加待办
  585. ActionLog::logAdd($this->post['token'], [
  586. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  587. "status" => $zxinfo['status'],//这里的status是之前的值
  588. "action_remark" => '',//备注
  589. "action_type" => "edit"//新建create,编辑edit,更改状态status
  590. ], "ZXD", $zxinfo['status'], $zxinfo);
  591. }
  592. //更新consule_order记录
  593. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  594. 'updatetime'=>date('Y-m-d H:i:s')]);
  595. if($op==false){
  596. Db::rollback();
  597. return error_show(1004,'咨询单结束时间更新失败');
  598. }
  599. //维护台账记录
  600. $insert_standing_book_data=[
  601. 'standBookNo'=>makeNo('IO'),
  602. 'infoNo'=>$innew,
  603. 'addtime' => date('Y-m-d H:i:s'),
  604. 'updatetime' => date('Y-m-d H:i:s')
  605. ];
  606. $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
  607. if(!empty($temp_project)){
  608. $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
  609. $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
  610. $insert_standing_book_data['customer_code']=$temp_project['khNo'];
  611. }
  612. Db::name('standing_book')->insert($insert_standing_book_data);
  613. Db::commit();
  614. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  615. }
  616. }catch (\Exception $e){
  617. Db::rollback();
  618. return error_show(1004,$e->getMessage());
  619. }
  620. }
  621. //** 发布竞标任务 */
  622. public function bargain(){
  623. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  624. if($infoNo==""){
  625. return error_show(1004,"参数infoNo不能为空");
  626. }
  627. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  628. if($zxinfo==false){
  629. return error_show(1004,"未找到信息数据");
  630. }
  631. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  632. if($status===""){
  633. return error_show(1004,"参数status不能为空");
  634. }
  635. // if($status==1&&$zxinfo['status']>1){
  636. // $zxinfo['bargain_num']=+1;
  637. // }
  638. $old_zxinfo_status = $zxinfo['status'];
  639. $zxinfo['status']=$status;
  640. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  641. $up = Db::name("consult_info")->save($zxinfo);
  642. if($up){
  643. //修改状态,添加待办
  644. ActionLog::logAdd($this->post['token'], [
  645. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  646. "status" => $old_zxinfo_status,//这里的status是之前的值
  647. "action_remark" => '',//备注
  648. "action_type" => "status"//新建create,编辑edit,更改状态status
  649. ], "ZXD", $zxinfo['status'], $zxinfo);
  650. return app_show(0,"状态更新成功");
  651. }else{
  652. return error_show(1003,"状态更新失败");
  653. }
  654. }
  655. //反馈商品添加
  656. public function feadback(){
  657. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  658. if($infoNo==""){
  659. return error_show(1002,"参数infoNo不能为空");
  660. }
  661. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  662. if($zxinfo==false){
  663. return error_show(1003,"未找到信息数据");
  664. }
  665. if($zxinfo['status']!=1){
  666. return error_show(1004,"任务未进行");
  667. }
  668. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  669. if($zx==false){
  670. return error_show(1003,"未找咨询信息数据");
  671. }
  672. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  673. if($pname==""){
  674. return error_show(1002,"参数pname不能为空");
  675. }
  676. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  677. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  678. if($cat_id==""){
  679. return error_show(1002,"参数cat_id不能为空");
  680. }
  681. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  682. if($specin==""){
  683. return error_show(1003,"参数specinfo不能为空");
  684. }
  685. $specinfo=[];
  686. foreach ($specin as $v){
  687. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  688. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  689. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  690. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  691. $specinfo[]=$v;
  692. }
  693. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  694. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  695. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  696. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  697. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  698. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day']) :"";
  699. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  700. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  701. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  702. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  703. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  704. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  705. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  706. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  707. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  708. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  709. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  710. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  711. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  712. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  713. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  714. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  715. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  716. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  717. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  718. if($nake_fee==="" ){
  719. return error_show(1004,"参数nake_fee不能为空");
  720. }
  721. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  722. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  723. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  724. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  725. if($delivery_place==''){
  726. return error_show(1002,"参数delivery_place不能为空");
  727. }
  728. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  729. if($token==''){
  730. return error_show(1002,"参数token不能为空");
  731. }
  732. $user =GetUserInfo($token);
  733. if(empty($user)||$user['code']!=0){
  734. return error_show(1005,"用户数据不存在");
  735. }
  736. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  737. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  738. $bidNo=makeNo("BD");
  739. $spucode=makeNo("SKU");
  740. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  741. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  742. //部分参数的大小校验
  743. $vali = Validate::rule([
  744. 'expire_day|有效时长'=>'require|elt:214748364',
  745. 'delivery_day|物流时长'=>'require|elt:214748364',
  746. 'work_day|生产工期'=>'require|elt:214748364',
  747. 'weight|总重量'=>'require|max:10',
  748. ]);
  749. $temp = [
  750. 'expire_day'=>$expire_day,
  751. 'delivery_day'=>$delivery_day,
  752. 'work_day'=>$work_day,
  753. 'weight'=>$weight,
  754. ];
  755. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  756. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  757. $cat_top_list = made($cat_id);
  758. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  759. if ($is_gold_price == 1 && $cat_top_id == 6) {
  760. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  761. ->find();
  762. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  763. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  764. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  765. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  766. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  767. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  768. $saleprice = $total_fee/ (1 - $budget);
  769. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  770. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  771. }else{
  772. if($nake_fee){
  773. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  774. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  775. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  776. }else{
  777. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  778. (1 - $budget);
  779. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  780. }
  781. }
  782. $supplier = Db::name('supplier')
  783. ->field('id,person,personid')
  784. ->where('code',$supplierNo)
  785. ->findOrEmpty();
  786. $data=[
  787. "bidNo"=>$bidNo,
  788. "infoNo"=>$infoNo,
  789. "zxNo"=>$zxinfo['zxNo'],
  790. "spuCode"=>$spucode,
  791. "good_name"=>$pname,
  792. "brand_id"=>$brandid,
  793. "cat_id"=>$cat_id,
  794. "specinfo"=>json_encode($specinfo),
  795. "unit_id"=>$unit_id,
  796. "cost_desc"=>$cost_desc,
  797. "work_day"=>$work_day,
  798. "delivery_day"=>$delivery_day,
  799. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  800. "expire_day"=>$expire_day,
  801. "origin_place"=>$origin_place,
  802. "supplierNo"=>$supplierNo,
  803. "pay_way"=>$pay_way,
  804. "tax"=>$tax,
  805. "send_way"=>$send_way,
  806. "metal_id"=>$metal_id,
  807. "is_gold_price"=>$is_gold_price,
  808. "config"=>$config,
  809. "other_config"=>$other_config,
  810. "weight"=>$weight,
  811. "good_weight"=>$good_weight,
  812. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  813. "is_diff"=>$is_diff,
  814. "demo_fee"=>$demo_fee,
  815. "delivery_fee"=>$delivery_fee,
  816. "open_fee"=>$open_fee,
  817. "pakge_fee"=>$pakge_fee,
  818. "nake_fee"=>$nake_fee,
  819. "mark_fee"=>$mark_fee,
  820. "cert_fee"=>$cert_fee,
  821. "cost_fee"=>$cost_fee,
  822. "total_fee"=>$total_fee,
  823. "supply_area"=>$supply_area,
  824. "remark"=>$remark,
  825. "sale_price"=>$saleprice,
  826. "sale_cost_fee"=>$sale_cost_fee,
  827. "origin_cost_fee"=>$sale_cost_fee,
  828. "origin_price"=>$saleprice,
  829. "createrid"=>$createrid,
  830. "creater"=>$creater,
  831. "status"=>$zxinfo['status']==1 ?1 :2,
  832. "is_del"=>0,
  833. "addtime"=>date("Y-m-d H:i:s"),
  834. "updatetime"=>date("Y-m-d H:i:s"),
  835. 'delivery_place'=>$delivery_place,//发货地
  836. 'cgder' => $supplier['person'] ?? '',
  837. 'cgderid' => $supplier['personid'] ?? 0,
  838. ];
  839. Db::startTrans();
  840. try{
  841. $insert= Db::name("consult_bids")->insert($data);
  842. if($insert){
  843. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  844. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  845. if($projectinfo==false){
  846. Db::rollback();
  847. return error_show(1006,"未找到项目信息");
  848. }
  849. $temp=[];
  850. $temp['spuCode']=$spucode;
  851. $temp['skuCode']="";
  852. $temp['pgNo']=$zxinfo['pgNo'];
  853. $temp['projectNo']=$zx['projectNo'];
  854. $temp['good_name']=$pname;
  855. $temp['good_type']=$projectinfo['good_type'];
  856. $temp['data_source']=2;
  857. $temp['cat_id']=$cat_id;
  858. $temp['budget_price']=$projectinfo['budget_price'];
  859. $temp['sale_price']=$saleprice;
  860. $temp['origin_price']=$total_fee;
  861. $temp['num']=$zxinfo['num'];
  862. $temp['status']=0;
  863. $temp['is_del']=0;
  864. $temp['creater']=$creater;
  865. $temp['createrid']=$createrid;
  866. $temp['addtime']=date("Y-m-d H:i:s");
  867. $temp['updatetime']=date("Y-m-d H:i:s");
  868. $nu = Db::name("project_feedback")->insert($temp);
  869. if($nu==false){
  870. Db::rollback();
  871. return error_show(1006,"项目反馈失败");
  872. }else{
  873. $old_projectinfo_status = $projectinfo['status'];
  874. $projectinfo['status']=2;
  875. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  876. $up = Db::name("project_info")->save($projectinfo);
  877. if($up){
  878. //修改状态,添加待办,只记录动作
  879. ActionLog::logAdd($this->post['token'], [
  880. "order_code" => $projectinfo['pgNo'],//编码
  881. "status" => $old_projectinfo_status,//这里的status是之前的值
  882. "action_remark" => '',//备注
  883. "action_type" => "status"//新建create,编辑edit,更改状态status
  884. ], "PRI", 2, $projectinfo);
  885. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  886. ->count();
  887. if($count==0){
  888. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  889. if($projetc!=false){
  890. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  891. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  892. if($proc==false){
  893. Db::rollback();
  894. return error_show(1006,"项目反馈失败");
  895. }else{
  896. //修改状态,添加待办
  897. ActionLog::logAdd($this->post['token'], [
  898. "order_code" => $projetc['projectNo'],//项目编码
  899. "status" => 1,//这里的status是之前的值
  900. "action_remark" => '',//备注
  901. "action_type" => "status"//新建create,编辑edit,更改状态status
  902. ], "PRO", 2, $projetc);
  903. ProcessOrder::AddProcess($this->post['token'], [
  904. "order_type" => 'PRO',
  905. "order_code" => $projetc['projectNo'],
  906. "order_id" => $projetc['id'],
  907. "order_status" => 2,"before_status"=>1
  908. ]);
  909. }
  910. }
  911. }
  912. }
  913. }
  914. }
  915. Db::commit();
  916. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  917. }else{
  918. Db::rollback();
  919. return error_show(1006,"反馈失败");
  920. }
  921. }catch (\Exception $e){
  922. Db::rollback();
  923. return error_show(1006,$e->getMessage());
  924. }
  925. }
  926. //反馈商品详情
  927. public function feadinfo(){
  928. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  929. if($bidNo==""){
  930. return error_show(1004,"参数bidNo不能为空");
  931. }
  932. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  933. if($info==false){
  934. return error_show(1004,"未找到商品数据");
  935. }
  936. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  937. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  938. $info['cat_info'] = made($info['cat_id'],[]);
  939. $info['noble_weight'] = $info['good_weight'];
  940. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  941. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  942. if($info['brand_id']!=0){
  943. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  944. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  945. }else{
  946. $info["brand_name"]="";
  947. $info["brand_id"]="";
  948. }
  949. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  950. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  951. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  952. $god=[
  953. "metal_id"=>$info['metal_id'],
  954. "weight"=>$info["good_weight"],
  955. "demo_fee"=>$info["demo_fee"],
  956. "delivery_fee"=>$info["delivery_fee"],
  957. "open_fee"=>$info["open_fee"],
  958. "packing_fee"=>$info["pakge_fee"],
  959. "mark_fee"=>$info["mark_fee"],
  960. "nake_fee"=>$info["nake_fee"],
  961. "cert_fee"=>$info["cert_fee"],
  962. "cost_fee"=>$info["cost_fee"],
  963. "num"=>$bidinfo["num"],
  964. ];
  965. if($info['is_gold_price']==1){
  966. $price = GoldPrice($god, $budget/100);
  967. $info['sale_price'] =round($price,2);
  968. }
  969. $info['specinfo'] = json_decode($info['specinfo'],true);
  970. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  971. if($info['delivery_place']!=""){
  972. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  973. }
  974. $info['delivery_place_cn']=GetAddr(json_encode($place));
  975. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  976. if($info['origin_place']!=""){
  977. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  978. }
  979. $info['origin_place_cn']=GetAddr(json_encode($place));
  980. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  981. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  982. $info['bargain'] =$bargain;
  983. $info['good_img'] = explode(',',$info['good_img']);
  984. //添加商品创建人字段
  985. $good_info = Db::name('good_basic')
  986. ->field('id,createrid,creater')
  987. ->where('is_del',0)
  988. ->where('spuCode',$info['spuCode'])
  989. ->findOrEmpty();
  990. $info['good_createrid'] = $good_info['createrid']??0;
  991. $info['good_creater'] = $good_info['creater']??'';
  992. return app_show(0,"获取成功",$info);
  993. }
  994. //反馈商品编辑
  995. public function feededit(){
  996. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  997. if($bidNo==""){
  998. return error_show(1002,"参数bidNo不能为空");
  999. }
  1000. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  1001. if($bidinfo==false){
  1002. return error_show(1003,"未找到信息数据");
  1003. }
  1004. if($bidinfo['status']>=5){
  1005. return error_show(1004,"咨询单已确认无法修改");
  1006. }
  1007. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  1008. if($zxinfo==false){
  1009. return error_show(1003,"未找到信息数据");
  1010. }
  1011. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  1012. if($zx==false){
  1013. return error_show(1003,"未找咨询信息数据");
  1014. }
  1015. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  1016. if($pname==""){
  1017. return error_show(1002,"参数pname不能为空");
  1018. }
  1019. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  1020. // if($brandid==""){
  1021. // return error_show(1002,"参数brandid不能为空");
  1022. // }
  1023. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  1024. if($cat_id==""){
  1025. return error_show(1002,"参数cat_id不能为空");
  1026. }
  1027. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  1028. if($specin==""){
  1029. return error_show(1003,"参数specinfo不能为空");
  1030. }
  1031. $specinfo=[];
  1032. foreach ($specin as $v){
  1033. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  1034. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  1035. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  1036. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  1037. $specinfo[]=$v;
  1038. }
  1039. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  1040. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  1041. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  1042. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  1043. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  1044. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  1045. :"";
  1046. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  1047. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1048. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  1049. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  1050. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  1051. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  1052. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  1053. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  1054. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  1055. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  1056. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  1057. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  1058. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  1059. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  1060. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1061. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1062. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1063. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1064. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1065. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1066. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1067. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1068. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1069. if($delivery_place==''){
  1070. return error_show(1002,"参数delivery_place不能为空");
  1071. }
  1072. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1073. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1074. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1075. $cat_top_list = made($cat_id);
  1076. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1077. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1078. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1079. ->find();
  1080. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1081. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1082. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1083. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1084. $saleprice = $total_fee / (1 - $budget);
  1085. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1086. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1087. }else{
  1088. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1089. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1090. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1091. }
  1092. Db::startTrans();
  1093. try{
  1094. $data=[
  1095. "good_name"=>$pname,
  1096. "brand_id"=>$brandid,
  1097. "cat_id"=>$cat_id,
  1098. "specinfo"=>json_encode($specinfo),
  1099. // "material"=>$material,
  1100. "unit_id"=>$unit_id,
  1101. "cost_desc"=>$cost_desc,
  1102. "work_day"=>$work_day,
  1103. "delivery_day"=>$delivery_day,
  1104. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1105. "expire_day"=>$expire_day,
  1106. "origin_place"=>$origin_place,
  1107. "supplierNo"=>$supplierNo,
  1108. "pay_way"=>$pay_way,
  1109. "tax"=>$tax,
  1110. "send_way"=>$send_way,
  1111. "metal_id"=>$metal_id,
  1112. "is_gold_price"=>$is_gold_price,
  1113. "config"=>$config,
  1114. "other_config"=>$other_config,
  1115. "weight"=>$weight,
  1116. "good_weight"=>$noble_weight,
  1117. "is_diff"=>$is_diff,
  1118. "demo_fee"=>$demo_fee,
  1119. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1120. "delivery_fee"=>$delivery_fee,
  1121. "open_fee"=>$open_fee,
  1122. "pakge_fee"=>$pakge_fee,
  1123. "nake_fee"=>$nake_fee,
  1124. "mark_fee"=>$mark_fee,
  1125. "cert_fee"=>$cert_fee,
  1126. "cost_fee"=>$cost_fee,
  1127. "sale_cost_fee"=>$sale_cost_fee,
  1128. "origin_cost_fee"=>$sale_cost_fee,
  1129. "total_fee"=>$total_fee,
  1130. "sale_price"=>$saleprice,
  1131. "origin_price"=>$saleprice,
  1132. "supply_area"=>$supply_area,
  1133. "remark"=>$remark,
  1134. "status"=>0,
  1135. "updatetime"=>date("Y-m-d H:i:s"),
  1136. 'delivery_place' => $delivery_place
  1137. ];
  1138. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1139. if($insert){
  1140. if($zxinfo['bargain_status']==1){
  1141. $zxinfo['bargain_status']=0;
  1142. $infoip =Db::name("consult_info")->save($zxinfo);
  1143. if($infoip==false){
  1144. Db::rollback();
  1145. return error_show(1006,"咨询信息状态更新失败");
  1146. }
  1147. }
  1148. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1149. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1150. if($projectinfo==false){
  1151. Db::rollback();
  1152. return error_show(1006,"未找到项目信息");
  1153. }
  1154. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1155. if($feed!=false) {
  1156. $feed['good_name']=$pname;
  1157. $feed['good_type']=$projectinfo['good_type'];
  1158. $feed['cat_id']=$cat_id;
  1159. $feed['sale_price']=$saleprice;
  1160. $feed['origin_price']=$total_fee;
  1161. $feed['updatetime']=date("Y-m-d H:i:s");
  1162. $temp['updatetime']=date("Y-m-d H:i:s");
  1163. $nu=Db::name("project_feedback")->save($feed);
  1164. if ($nu == false) {
  1165. Db::rollback();
  1166. return error_show(1006 , "项目反馈失败");
  1167. } else {
  1168. $old_projectinfo_status=$projectinfo['status'];
  1169. $projectinfo['status']=2;
  1170. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1171. $up=Db::name("project_info")->save($projectinfo);
  1172. if ($up) {
  1173. //修改状态,添加待办,只记录动作
  1174. ActionLog::logAdd($this->post['token'] , [
  1175. "order_code"=>$projectinfo['pgNo'] ,//编码
  1176. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1177. "action_remark"=>'' ,//备注
  1178. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1179. ] , "PRI" , 2 , $projectinfo
  1180. );
  1181. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1182. if ($count == 0) {
  1183. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1184. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1185. if ($project_id) {
  1186. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1187. if ($proc == false) {
  1188. Db::rollback();
  1189. return error_show(1006 , "项目反馈失败");
  1190. } else {
  1191. //修改状态,添加待办
  1192. ActionLog::logAdd($this->post['token'] , [
  1193. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1194. "status"=>1 ,//这里的status是之前的值
  1195. "action_remark"=>'' ,//备注
  1196. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1197. ] , "PRO" , 2 , $this->post
  1198. );
  1199. ProcessOrder::AddProcess($this->post['token'] , [
  1200. "order_type"=>'PRO' ,
  1201. "order_code"=>$projectinfo['projectNo'] ,
  1202. "order_id"=>$project_id ,
  1203. "order_status"=>2 , "before_status"=>1
  1204. ]
  1205. );
  1206. }
  1207. }
  1208. }
  1209. }
  1210. }
  1211. }
  1212. }
  1213. Db::commit();
  1214. return app_show(0,"编辑成功");
  1215. }else{
  1216. Db::rollback();
  1217. return error_show(1004,"编辑失败");
  1218. }
  1219. }catch (\Exception $e){
  1220. Db::rollback();
  1221. return error_show(1004,$e->getMessage());
  1222. }
  1223. }
  1224. //生成议价单
  1225. public function bargain_add(){
  1226. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1227. if($bidNo===""){
  1228. return error_show(1004,"参数bidNo不能为空");
  1229. }
  1230. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1231. if($info==false){
  1232. return error_show(1004,"未找到商品数据");
  1233. }
  1234. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1235. if($consult==false){
  1236. return error_show(1004,"未找到咨询数据");
  1237. }
  1238. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1239. if($bargain_price===""){
  1240. return error_show(1004,"参数bargain_price不能为空");
  1241. }
  1242. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1243. if($info['is_gold_price']==1){
  1244. if($cost_price==""){
  1245. return error_show(1004,"参数cost_price不能为空");
  1246. }
  1247. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1248. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1249. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1250. ->find();
  1251. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1252. }
  1253. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1254. // if($bargain_reason===""){
  1255. // return error_show(1004,"参数bargain_reason不能为空");
  1256. // }
  1257. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1258. if($infos==false){
  1259. return error_show(1004,"未找到商品数据");
  1260. }
  1261. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1262. return error_show(1004,"咨询单招标未结束或已确认商品");
  1263. }
  1264. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1265. if($token==''){
  1266. return error_show(105,"参数token不能为空");
  1267. }
  1268. $user =GetUserInfo($token);
  1269. if(empty($user)||$user['code']!=0){
  1270. return error_show(1002,"用户数据不存在");
  1271. }
  1272. //新增两个字段
  1273. //议价备注
  1274. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1275. //议价原因id
  1276. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1277. if ($result_info_id != '') {
  1278. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1279. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1280. }
  1281. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1282. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1283. $bargainNo =makeNo("BA");
  1284. Db::startTrans();//::todo 金价 毛利计算
  1285. try{
  1286. $data=[
  1287. "bidsNo"=>$bidNo,
  1288. "infoNo"=>$info['infoNo'],
  1289. "zxNo"=>$info['zxNo'],
  1290. "bargainNo"=>$bargainNo,
  1291. "bargain_type"=>1,
  1292. "bargain_reason"=>$bargain_reason,
  1293. "sale_price"=>$info['sale_price'],
  1294. "cost_before_price"=>$info['sale_cost_fee'],
  1295. "cost_after_price"=>$cost_price,
  1296. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1297. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1298. "after_price"=>$bargain_price,
  1299. "exam_info"=>"",
  1300. "status"=>0,
  1301. "is_del"=>0,
  1302. "creater"=>$creater,
  1303. "createrid"=>$createrid,
  1304. "addtime"=>date("Y-m-d H:i:s"),
  1305. "updatetime"=>date("Y-m-d H:i:s"),
  1306. 'bargain_remark'=>$bargain_remark,
  1307. 'result_info_id'=>$result_info_id,
  1308. ];
  1309. $int = Db::name("bargain_order")->insertGetId($data);
  1310. if($int){
  1311. //修改状态,添加待办
  1312. ActionLog::logAdd($this->post['token'], [
  1313. "order_code" => $bargainNo,//咨询单详情编号
  1314. "status" => 0,//这里的status是之前的值
  1315. "action_remark" => '',//备注
  1316. "action_type" => "status"//新建create,编辑edit,更改状态status
  1317. ], "YJD", $data['status'], $data);
  1318. ProcessOrder::AddProcess($this->post['token'], [
  1319. "order_type" => 'YJD',
  1320. "order_code" => $bargainNo,
  1321. "order_id" => $int,
  1322. "order_status" =>0,
  1323. "before_status"=>0,
  1324. 'holder_id'=>$data['createrid']
  1325. ]);
  1326. $odlstatus=$info['status'];
  1327. $info['status']=3;
  1328. $info['updatetime']=date("Y-m-d H:i:s");
  1329. $up =Db::name("consult_bids")->save($info);
  1330. if($up){
  1331. //修改状态,添加待办
  1332. ActionLog::logAdd($this->post['token'], [
  1333. "order_code" => $bidNo,//咨询单详情编号
  1334. "status" => $odlstatus,//这里的status是之前的值
  1335. "action_remark" => '',//备注
  1336. "action_type" => "status"//新建create,编辑edit,更改状态status
  1337. ], "FKD", $info['status'], $info);
  1338. $old_infos_status = $infos['status'];
  1339. $infos['status']=3;
  1340. $infos['updatetime']=date("Y-m-d H:i:s");
  1341. $ups =Db::name("consult_info")->save($infos);
  1342. if($ups){
  1343. //修改状态,添加待办
  1344. ActionLog::logAdd($this->post['token'], [
  1345. "order_code" => $infos['infoNo'],//咨询单详情编号
  1346. "status" => $old_infos_status,//这里的status是之前的值
  1347. "action_remark" => '',//备注
  1348. "action_type" => "status"//新建create,编辑edit,更改状态status
  1349. ], "ZXD", $infos['status'], $infos);
  1350. //维护台账信息
  1351. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1352. Db::commit();
  1353. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1354. }
  1355. }
  1356. }
  1357. Db::rollback();
  1358. return error_show(1004,"议价单新建失败");
  1359. }catch (\Exception $e){
  1360. Db::rollback();
  1361. return error_show(1004,$e->getMessage());
  1362. }
  1363. }
  1364. //选择商品
  1365. public function bids_check(){
  1366. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1367. if($bidNo===""){
  1368. return error_show(1004,"参数bidNo不能为空");
  1369. }
  1370. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1371. if($info==false){
  1372. return error_show(1004,"未找到商品数据");
  1373. }
  1374. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1375. if($infos==false){
  1376. return error_show(1004,"未找到商品数据");
  1377. }
  1378. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1379. return error_show(1004,"咨询单招标未结束或已确认商品");
  1380. }
  1381. Db::startTrans();
  1382. try {
  1383. $oldstattus=$info['status'];
  1384. $info['status']=6;
  1385. $info['updatetime']=date("Y-m-d H:i:s");
  1386. $bids = Db::name("consult_bids")->save($info);
  1387. if($bids){
  1388. //修改状态,添加待办
  1389. ActionLog::logAdd($this->post['token'], [
  1390. "order_code" =>$bidNo,//咨询单详情编号
  1391. "status" => $oldstattus,//这里的status是之前的值
  1392. "action_remark" => '',//备注
  1393. "action_type" => "status"//新建create,编辑edit,更改状态status
  1394. ], "FKD", $info['status'], $info);
  1395. $old_infos_status = $infos['status'];
  1396. $infos['status']=4;
  1397. $infos['updatetime']=date("Y-m-d H:i:s");
  1398. $se = Db::name("consult_info")->save($infos);
  1399. if($se){
  1400. //修改状态,添加待办
  1401. ActionLog::logAdd($this->post['token'], [
  1402. "order_code" => $infos['infoNo'],//咨询单详情编号
  1403. "status" => $old_infos_status,//这里的status是之前的值
  1404. "action_remark" => '',//备注
  1405. "action_type" => "status"//新建create,编辑edit,更改状态status
  1406. ], "ZXD", $infos['status'], $infos);
  1407. Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
  1408. ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
  1409. Db::commit();
  1410. return app_show(0,"商品确定成功");
  1411. }
  1412. }
  1413. Db::rollback();
  1414. return error_show(1004,"商品确认失败");
  1415. }catch (\Exception $e){
  1416. Db::rollback();
  1417. return error_show(1004,$e->getMessage());
  1418. }
  1419. }
  1420. //议价审核
  1421. /**
  1422. * status:
  1423. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1424. */
  1425. public function bargain_status(){
  1426. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1427. if($bargainNo===""){
  1428. return error_show(1004,"参数bargainNo不能为空");
  1429. }
  1430. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1431. if($info==false){
  1432. return error_show(1004,"未找到议价数据");
  1433. }
  1434. if($info['status']==12){
  1435. return error_show(1004,"议价单已取消");
  1436. }
  1437. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1438. if($bids==false){
  1439. return error_show(1004,"未找到商品数据");
  1440. }
  1441. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1442. if($coninfo==false){
  1443. return error_show(1004,"未找到咨询单数据");
  1444. }
  1445. if($bids['status']==6){
  1446. return error_show(1004,"咨询已选择商品");
  1447. }
  1448. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1449. if($status===''){
  1450. return error_show(1005,"参数status不能为空");
  1451. }
  1452. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1453. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1454. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1455. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1456. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1457. if($bids['is_gold_price']==1){
  1458. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1459. ->find();
  1460. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1461. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1462. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1463. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1464. $saleprice =$total_fe / (1 - $budget);
  1465. $rate_price = $total_fe / (1 - $rate);
  1466. $money_price =$total_fe / (1 - $money_rate);
  1467. $lower_price =$total_fe / (1 - $lower_rate);
  1468. }else{
  1469. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1470. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1471. if($bids['nake_fee']!=0){
  1472. $saleprice = ($total_fe)/ (1 - $budget);
  1473. $rate_price = ($total_fe)/ (1 - $rate);
  1474. $money_price =($total_fe)/ (1 - $money_rate);
  1475. $lower_price = ($total_fe) / (1 - $lower_rate);
  1476. }else{
  1477. $saleprice = $total_fe / (1 - $budget);
  1478. $rate_price =$total_fe/ (1 - $rate);
  1479. $money_price =$total_fe / (1 - $money_rate);
  1480. $lower_price = $total_fe/ (1 - $lower_rate);
  1481. }
  1482. }
  1483. $ra_status = $info['status'];
  1484. if($status==1){
  1485. if($info['status']==0){
  1486. if($info['after_price']<$rate_price){
  1487. $info['status']=2;
  1488. }else{
  1489. $info['status']=1;
  1490. }
  1491. }elseif($info['status']==2){
  1492. $info['status']=4;
  1493. }elseif($info['status']==4||$info['status']==5){
  1494. if($info['after_price']<$money_price){
  1495. $info['status']=7;
  1496. }else{
  1497. $info['status']=6;
  1498. }
  1499. }elseif($info['status']==7){
  1500. $info['lower_price'] =$lower_price;
  1501. if($info['after_price']<$lower_price){
  1502. $info['status']=10;
  1503. }else{
  1504. $info['status']=9;
  1505. }
  1506. }
  1507. }else{
  1508. if($info['status']==0){
  1509. $info['status']=3;
  1510. }elseif($info['status']==2){
  1511. $info['status']=4;
  1512. }elseif($info['status']==4||$info['status']==5){
  1513. $info['status']=8;
  1514. }elseif($info['status']==7){
  1515. $info['lower_price'] =$lower_price;
  1516. $info['status']=11;
  1517. }
  1518. }
  1519. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1520. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1521. if($token==''){
  1522. return error_show(105,"参数token不能为空");
  1523. }
  1524. $user =GetUserInfo($token);
  1525. if(empty($user)||$user['code']!=0){
  1526. return error_show(1002,"用户数据不存在");
  1527. }
  1528. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1529. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1530. Db::startTrans();
  1531. try{
  1532. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1533. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1534. "creater"=>$creater];
  1535. // $info['status'] =$status;
  1536. $info['remark'] =$remark;
  1537. $info['exam_info']=json_encode($examinfo) ;
  1538. $info['updatetime'] =date("Y-m-d H:i:s");
  1539. $up =Db::name("bargain_order")->save($info);
  1540. if($up){
  1541. //修改状态,添加待办
  1542. ActionLog::logAdd($this->post['token'], [
  1543. "order_code" => $bargainNo,//咨询单详情编号
  1544. "status" =>$ra_status,//这里的status是之前的值
  1545. "action_remark" => '',//备注
  1546. "action_type" => "status"//新建create,编辑edit,更改状态status
  1547. ], "YJD", $info['status'], $info);
  1548. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status,'holder_id'=>$info['createrid']];
  1549. ProcessOrder::AddProcess($token,$process);
  1550. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1551. $bidstatus=$bids['status'];
  1552. $bids['status']=5;
  1553. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1554. $bids['sale_price']=$info['after_price'];
  1555. if($bids['is_gold_price']==1){
  1556. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1557. // ->find();
  1558. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1559. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1560. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1561. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1562. }
  1563. }
  1564. $bids['updatetime']=date("Y-m-d H:i:s");
  1565. $up =Db::name("consult_bids")->save($bids);
  1566. if($up==false){
  1567. Db::rollback();
  1568. return error_show(1004,"数据更新失败");
  1569. }
  1570. ActionLog::logAdd($this->post['token'], [
  1571. "order_code" => $info["bidsNo"],//咨询单详情编号
  1572. "status" => $bidstatus,//这里的status是之前的值
  1573. "action_remark" => '',//备注
  1574. "action_type" => "status"//新建create,编辑edit,更改状态status
  1575. ], "FKD", $bids['status'], $bids);
  1576. }
  1577. Db::commit();
  1578. return app_show(0,"更新成功");
  1579. }
  1580. }catch (\Exception $e){
  1581. Db::rollback();
  1582. return error_show(1004,$e->getMessage());
  1583. }
  1584. }
  1585. public function bargain_info(){
  1586. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1587. if($bargainNo===""){
  1588. return error_show(1004,"参数bargainNo不能为空");
  1589. }
  1590. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1591. if($info==false){
  1592. return error_show(1004,"未找到议价数据");
  1593. }
  1594. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1595. if($bidinfos==false){
  1596. return error_show(1004,"未找到商品数据");
  1597. }
  1598. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1599. if($consultinfos==false){
  1600. return error_show(1004,"未找到咨询商品数据");
  1601. }
  1602. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1603. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1604. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1605. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1606. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1607. $info['before_rate'] =round($info['before_rate']*100,2);
  1608. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1609. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1610. $info['after_rate'] = round($info['after_rate']*100,2);
  1611. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1612. if($bidinfos['brand_id']!=0){
  1613. $info['brand_id'] = $bidinfos['brand_id'];
  1614. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1615. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1616. }else{
  1617. $info["brand_name"]="";
  1618. $info["brand_id"]="";
  1619. }
  1620. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1621. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1622. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1623. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1624. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1625. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1626. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1627. $info['budget'] =$budget;
  1628. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1629. if($info['after_rate']>=$catinfo['rate']){
  1630. //业务主管利率
  1631. $info['rate_status'] =1;
  1632. }
  1633. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1634. //财务主管利率
  1635. $info['rate_status'] =2;
  1636. }
  1637. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1638. //boss利率
  1639. $info['rate_status'] =3;
  1640. }
  1641. $god=[
  1642. "metal_id"=>$bidinfos['metal_id'],
  1643. "weight"=>$bidinfos["good_weight"],
  1644. "demo_fee"=>$bidinfos["demo_fee"],
  1645. "delivery_fee"=>$bidinfos["delivery_fee"],
  1646. "open_fee"=>$bidinfos["open_fee"],
  1647. "packing_fee"=>$bidinfos["pakge_fee"],
  1648. "mark_fee"=>$bidinfos["mark_fee"],
  1649. "nake_fee"=>$bidinfos["nake_fee"],
  1650. "cert_fee"=>$bidinfos["cert_fee"],
  1651. "cost_fee"=>$bidinfos["cost_fee"],
  1652. "num"=>$bidinfoe["num"],
  1653. ];
  1654. $info['gold_price']=0;
  1655. $info['noble_weight']=$bidinfos['good_weight'];
  1656. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1657. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1658. ->find();
  1659. $info['gold_price'] =$gold['price'];
  1660. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1661. }else{
  1662. if($bidinfos['nake_fee']!=0){
  1663. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1664. }else{
  1665. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1666. }
  1667. }
  1668. $info['cost_desc'] =$bidinfos['cost_desc'];
  1669. $info['work_day'] =$bidinfos['work_day'];
  1670. $info['delivery_day'] =$bidinfos['delivery_day'];
  1671. $info['expire_day'] =$bidinfos['expire_day'];
  1672. $info['origin_place'] =$bidinfos['origin_place'];
  1673. $info['origin_addr'] ="";
  1674. if($bidinfos['origin_place']!=''){
  1675. $code = explode(",",$bidinfos['origin_place']);
  1676. $temp=[];
  1677. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1678. $temp['city_code']=isset($code[1])?$code[1]:"";
  1679. $temp['area_code']=isset($code[2])?$code[2]:"";
  1680. $addr= GetAddr(json_encode($temp));
  1681. $info['origin_addr'] = $addr;
  1682. }
  1683. $info['supplierNo'] =$bidinfos['supplierNo'];
  1684. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1685. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1686. $info['pay_way'] =$bidinfos['pay_way'];
  1687. $info['tax'] =$bidinfos['tax'];
  1688. $info['send_way'] =$bidinfos['send_way'];
  1689. $info['metal_id'] =$bidinfos['metal_id'];
  1690. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1691. $info['config'] =$bidinfos['config'];
  1692. $info['other_config'] =$bidinfos['other_config'];
  1693. $info['weight'] =$bidinfos['weight'];
  1694. $info['good_weight'] =$bidinfos['good_weight'];
  1695. $info['is_diff'] =$bidinfos['is_diff'];
  1696. $info['demo_fee'] =$bidinfos['demo_fee'];
  1697. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1698. $info['open_fee'] =$bidinfos['open_fee'];
  1699. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1700. $info['nake_fee'] =$bidinfos['nake_fee'];
  1701. $info['mark_fee'] =$bidinfos['mark_fee'];
  1702. $info['cert_fee'] =$bidinfos['cert_fee'];
  1703. $info['cost_fee'] =$bidinfos['cost_fee'];
  1704. $info['total_fee'] =$bidinfos['total_fee'];
  1705. $info['supply_area'] =$bidinfos['supply_area'];
  1706. $info['remark'] =$bidinfos['remark'];
  1707. $info['is_addrs'] =$consultinfos['is_addrs'];
  1708. $info['is_custom'] =$consultinfos['is_custom'];
  1709. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1710. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1711. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1712. if($info['status']==7){
  1713. $info['lower_price'] =round($lower_price,2);
  1714. }
  1715. //获取议价原因
  1716. if ($info['result_info_id'] != 0) {
  1717. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1718. } else {
  1719. $info['result_info'] = '';
  1720. }
  1721. return app_show(0,"获取成功",$info);
  1722. }
  1723. public function bidlist(){
  1724. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1725. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1726. $where=[['is_del',"=",0]];
  1727. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1728. if ($zxNo !== "") {
  1729. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1730. }
  1731. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1732. if ($infoNo !== "") {
  1733. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1734. }
  1735. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1736. if ($bidNo !== "") {
  1737. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1738. }
  1739. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1740. if ($pgNo !== "") {
  1741. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1742. $where[] = ['infoNo','in',$bidinfo];
  1743. }
  1744. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1745. if ($bargain_status !== "") {
  1746. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1747. $where[] = ['infoNo','in',$bidinfo];
  1748. }
  1749. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1750. if ($projectNo !== "") {
  1751. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1752. ("zxNo");
  1753. $where[] = ['zxNo','in',$zxlist];
  1754. }
  1755. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1756. if($is_own==1){
  1757. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1758. if($token==""){
  1759. return error_show(101,'token不能为空');
  1760. }
  1761. $apply_id =GetUserInfo($token);
  1762. if(empty($apply_id)||$apply_id['code']!=0){
  1763. return error_show(1002,"申请人数据不存在");
  1764. }
  1765. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1766. $where[]=['createrid',"=",$rm];
  1767. }
  1768. $count = Db::name('consult_bids')->where($where)->count();
  1769. $total = ceil($count / $size);
  1770. $page = $page >= $total ? $total : $page;
  1771. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1772. $data=[];
  1773. foreach ($list as $value){
  1774. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1775. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1776. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1777. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1778. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1779. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1780. if($value['brand_id']!=0){
  1781. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1782. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1783. }else{
  1784. $value["brand_name"]="";
  1785. $value["brand_id"]="";
  1786. }
  1787. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1788. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1789. $god=[
  1790. "metal_id"=>$value['metal_id'],
  1791. "weight"=>$value["good_weight"],
  1792. "demo_fee"=>$value["demo_fee"],
  1793. "delivery_fee"=>$value["delivery_fee"],
  1794. "open_fee"=>$value["open_fee"],
  1795. "packing_fee"=>$value["pakge_fee"],
  1796. "mark_fee"=>$value["mark_fee"],
  1797. "nake_fee"=>$value["nake_fee"],
  1798. "cert_fee"=>$value["cert_fee"],
  1799. // "cost_fee"=>$value["cost_fee"],
  1800. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1801. //暂时注掉,搞不清楚原因@吴广广
  1802. "num"=>$bidinfo["num"],
  1803. ];
  1804. $top_cat = made($value['cat_id']);
  1805. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1806. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1807. $price = GoldPrice($god, $budget/100);
  1808. $value['sale_price'] = round($price,2);
  1809. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1810. $value["origin_price"];
  1811. }
  1812. $value['cost_fee'] =$value['origin_cost_fee'];
  1813. $value['specinfo'] = json_decode($value['specinfo'],true);
  1814. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1815. $value['bargain_status']=$bidinfo['bargain_status'];
  1816. //reject驳回原因,status==5表示驳回
  1817. $value['reject']=[];
  1818. if ($value['status'] >=5) {
  1819. $value['reject'] = Db::name('bargain_order')
  1820. ->field('id,remark,status')
  1821. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1822. ->whereIn('status', [3,8,11])->order("id desc")
  1823. ->find();
  1824. }
  1825. //产地
  1826. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1827. if($value['delivery_place']!=""){
  1828. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1829. }
  1830. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1831. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1832. if($value['origin_place']!=""){
  1833. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1834. }
  1835. $value['origin_addr']=GetAddr(json_encode($place));
  1836. // if($value['origin_place']!=''){
  1837. // $code = explode(",",$value['origin_place']);
  1838. // $temp=[];
  1839. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1840. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1841. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1842. // $addr= GetAddr(json_encode($temp));
  1843. // $value['origin_addr'] = $addr;
  1844. // }
  1845. $good_info = Db::name('good_basic')
  1846. ->field('id,createrid,creater')
  1847. ->where('is_del',0)
  1848. ->where('spuCode',$value['spuCode'])
  1849. ->findOrEmpty();
  1850. $value['good_createrid']=$good_info['createrid']??$value['createrid'];
  1851. $value['good_creater']=$good_info['creater']??$value['creater'];
  1852. $data[] = $value;
  1853. }
  1854. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1855. }
  1856. public function feedlist(){
  1857. $where=[['is_del',"=",0]];
  1858. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1859. if ($zxNo !== "") {
  1860. $where[] = ['zxNo','=',$zxNo];
  1861. }
  1862. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1863. if ($infoNo !== "") {
  1864. $where[] = ['infoNo','=',$infoNo];
  1865. }
  1866. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1867. if ($bidNo !== "") {
  1868. $where[] = ['bidNo','=',$bidNo];
  1869. }
  1870. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1871. if ($projectNo !== "") {
  1872. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1873. ("zxNo");
  1874. $where[] = ['zxNo','in',$zxlist];
  1875. }
  1876. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1877. if($token==''){
  1878. return error_show(102,"参数token不能为空");
  1879. }
  1880. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1881. if($is_own==1){
  1882. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1883. if($token==""){
  1884. return error_show(101,'token不能为空');
  1885. }
  1886. $apply_id =GetUserInfo($token);
  1887. if(empty($apply_id)||$apply_id['code']!=0){
  1888. return error_show(1002,"申请人数据不存在");
  1889. }
  1890. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1891. $where[]=['createrid',"=",$rm];
  1892. }
  1893. $list =Db::name('consult_bids')->where($where)->select();
  1894. $data=[];
  1895. foreach ($list as $value){
  1896. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1897. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1898. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1899. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1900. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1901. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1902. if($value['brand_id']!=0){
  1903. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1904. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1905. }else{
  1906. $value["brand_name"]="";
  1907. $value["brand_id"]="";
  1908. }
  1909. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1910. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1911. $god=[
  1912. "metal_id"=>$value['metal_id'],
  1913. "weight"=>$value["good_weight"],
  1914. "demo_fee"=>$value["demo_fee"],
  1915. "delivery_fee"=>$value["delivery_fee"],
  1916. "open_fee"=>$value["open_fee"],
  1917. "packing_fee"=>$value["pakge_fee"],
  1918. "mark_fee"=>$value["mark_fee"],
  1919. "nake_fee"=>$value["nake_fee"],
  1920. "cert_fee"=>$value["cert_fee"],
  1921. "cost_fee"=>$value["cost_fee"],
  1922. "num"=>$bidinfo["num"],
  1923. ];
  1924. if ($value['is_gold_price'] == 1 ) {
  1925. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1926. ->find();
  1927. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1928. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1929. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1930. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1931. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1932. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1933. }else{
  1934. if($value["nake_fee"]){
  1935. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1936. }else{
  1937. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1938. (1 - $budget);
  1939. }
  1940. }
  1941. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1942. $value['specinfo'] = json_decode($value['specinfo'],true);
  1943. $value['bargain_status']=$bidinfo['bargain_status'];
  1944. $data[]=$value;
  1945. }
  1946. return app_show(0,"获取成功",$data);
  1947. }
  1948. public function bragain_list(){
  1949. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1950. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1951. $where=[['bo.is_del',"=",0]];
  1952. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1953. if($bidsNo!=""){
  1954. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1955. }
  1956. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1957. if ($zxNo !== "") {
  1958. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1959. }
  1960. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1961. if ($bargainNo !== "") {
  1962. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1963. }
  1964. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1965. if ($status!== "") {
  1966. $where[] = ['bo.status','=',$status];
  1967. }
  1968. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1969. if ($infoNo !== "") {
  1970. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1971. }
  1972. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1973. if ($projectNo !== "") {
  1974. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column("zxNo");
  1975. $where[] = ['bo.zxNo','in',$zxlist];
  1976. }
  1977. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1978. if ($pgNo !== "") {
  1979. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1980. $where[] = ['bo.infoNo','in',$bidinfo];
  1981. }
  1982. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1983. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1984. if($start!=""){
  1985. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1986. }
  1987. if($end!=""){
  1988. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1989. }
  1990. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1991. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1992. // $role=$this->checkRole();
  1993. // if(!empty($role['write'])){
  1994. // $where[]=["bo.createrid","in",$role['write']];
  1995. // }
  1996. // $role = $this->checkDataShare();
  1997. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['bo.createrid', 'in', $role[DataGroupModel::$type_全部]];
  1998. $role = $this->checkDataShare();
  1999. $hand = resign_hand_user($this->uid,0);
  2000. if (!empty($role[DataGroupModel::$type_全部])) {
  2001. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  2002. $where[] = ['bo.createrid', 'in',$arr];
  2003. }
  2004. $count=Db::name("bargain_order")
  2005. ->alias('bo')
  2006. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  2007. ->where($where)
  2008. ->count();
  2009. $total = ceil($count / $size);
  2010. $page = $page >= $total ? $total : $page;
  2011. $list = Db::name('bargain_order')
  2012. ->alias('bo')
  2013. ->field('bo.*,u.itemid')
  2014. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  2015. ->where($where)
  2016. ->page($page, $size)
  2017. ->order('bo.addtime', 'desc')
  2018. ->cursor();
  2019. $data=[];
  2020. foreach ($list as $value){
  2021. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  2022. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  2023. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  2024. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  2025. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  2026. if($bidinfos['brand_id']!=0){
  2027. $value['brand_id'] = $bidinfos['brand_id'];
  2028. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  2029. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  2030. }else{
  2031. $value["brand_name"]="";
  2032. $value["brand_id"]="";
  2033. }
  2034. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  2035. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  2036. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  2037. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  2038. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  2039. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  2040. $value['budget'] =$budget;
  2041. $god=[
  2042. "metal_id"=>$bidinfos['metal_id'],
  2043. "weight"=>$bidinfos["good_weight"],
  2044. "demo_fee"=>$bidinfos["demo_fee"],
  2045. "delivery_fee"=>$bidinfos["delivery_fee"],
  2046. "open_fee"=>$bidinfos["open_fee"],
  2047. "packing_fee"=>$bidinfos["pakge_fee"],
  2048. "mark_fee"=>$bidinfos["mark_fee"],
  2049. "nake_fee"=>$bidinfos["nake_fee"],
  2050. "cert_fee"=>$bidinfos["cert_fee"],
  2051. "cost_fee"=>$bidinfos["cost_fee"],
  2052. "num"=>$bidinfoe["num"],
  2053. ];
  2054. // if($bidinfos['is_gold_price']==1){
  2055. // $price = GoldPrice($god, $budget/100);
  2056. // }else{
  2057. // $price = GoodPrice($god, $budget/100);
  2058. // }
  2059. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  2060. $value['sale_price'] =round($bidinfos['origin_price'],2);
  2061. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  2062. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  2063. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2064. //是否具有编辑权限
  2065. $value['is_allow_update'] = 0;
  2066. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  2067. $data[]=$value;
  2068. }
  2069. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  2070. }
  2071. public function crontablist(){
  2072. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  2073. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  2074. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  2075. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2076. if ($zxNo !== "") {
  2077. $where[] = ['a.zxNo','=',$zxNo];
  2078. }
  2079. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  2080. if ($salesman !== "") {
  2081. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  2082. $where[]= ["b.salesman",'like',"%$salesman%"];
  2083. }
  2084. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  2085. if ($cpName !== "") {
  2086. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  2087. $where[]= ["a.good_Name",'like',"%$cpName%"];
  2088. }
  2089. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  2090. if ($khNo !== "") {
  2091. // $where['khNo'] = $khNo;
  2092. $where[]= ["b.khNo",'like',"%$khNo%"];
  2093. }
  2094. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2095. if ($start !="") {
  2096. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2097. $where[]= ["a.addtime",'>=',$start];
  2098. }
  2099. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2100. if($end !=""){
  2101. $where[]= ["a.addtime",'<=',$end];
  2102. }
  2103. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2104. if ($status !== "") {
  2105. $where[]= ["a.status",'=',$status];
  2106. }
  2107. // $role=$this->checkRole();
  2108. // if(!empty($role['platform']) ){
  2109. // $where[]=["b.platform_code","in",$role['platform']];
  2110. // }
  2111. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2112. ->count();
  2113. $total = ceil($count / $size);
  2114. $page = $page >= $total ? $total : $page;
  2115. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2116. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2117. $data=[];
  2118. foreach ($list as $value){
  2119. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2120. $cat =Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  2121. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  2122. $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget/100));
  2123. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2124. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2125. $value['khname']="";
  2126. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2127. true):[];
  2128. if($value['khNo']!==""){
  2129. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2130. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2131. }
  2132. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2133. ->find();
  2134. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2135. $value['is_feed'] =$consult==false?0:1;
  2136. $value['is_all_feed'] =$consults==false?0:1;
  2137. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2138. $data[]=$value;
  2139. }
  2140. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2141. }
  2142. //复制上面的bidlist方法,只更改排序方式
  2143. public function bidlistCopy()
  2144. {
  2145. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2146. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2147. $where = [['cb.is_del', "=", 0],['c.status','<>',6]];//不要'取消转单'状态下的数据
  2148. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2149. if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2150. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2151. if ($infoNo !== "") $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2152. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2153. if ($bidNo !== "") $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2154. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2155. if ($pgNo !== "") {
  2156. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2157. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2158. }
  2159. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2160. if ($bargain_status !== "") {
  2161. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2162. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2163. }
  2164. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2165. if ($projectNo !== "") {
  2166. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
  2167. $where[] = ['cb.zxNo', 'in', $zxlist];
  2168. }
  2169. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2170. if ($is_own == 1) {
  2171. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2172. if ($token == "") return error_show(101, 'token不能为空');
  2173. $apply_id = GetUserInfo($token);
  2174. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  2175. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2176. $where[] = ['cb.createrid', "=", $rm];
  2177. }
  2178. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2179. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2180. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  2181. if ($good_name !== "") $where[] = ["cb.good_name", 'like', '%' . $good_name . '%'];
  2182. $supplierName = isset($this->post['supplierName']) && $this->post['supplierName'] !== "" ? trim($this->post['supplierName']) : "";
  2183. if ($supplierName !== "") $where[] = ["s.name", 'like', '%' . $supplierName . '%'];
  2184. $count = Db::name('consult_bids')
  2185. ->alias('cb')
  2186. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2187. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2188. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2189. ->where($where)
  2190. ->count();
  2191. $total = ceil($count / $size);
  2192. $page = $page >= $total ? $total : $page;
  2193. $list = Db::name('consult_bids')
  2194. ->alias('cb')
  2195. ->field('cb.*,u.itemid,s.name supplierName')
  2196. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2197. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2198. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2199. ->where($where)
  2200. ->page($page, $size)
  2201. ->order('cb.addtime', 'desc')
  2202. ->cursor();
  2203. $data = [];
  2204. foreach ($list as $value) {
  2205. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2206. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2207. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2208. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2209. // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2210. // $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2211. if ($value['brand_id'] != 0) {
  2212. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2213. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2214. } else {
  2215. $value["brand_name"] = "";
  2216. $value["brand_id"] = "";
  2217. }
  2218. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2219. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2220. $god = [
  2221. "metal_id" => $value['metal_id'],
  2222. "weight" => $value["good_weight"],
  2223. "demo_fee" => $value["demo_fee"],
  2224. "delivery_fee" => $value["delivery_fee"],
  2225. "open_fee" => $value["open_fee"],
  2226. "packing_fee" => $value["pakge_fee"],
  2227. "mark_fee" => $value["mark_fee"],
  2228. "nake_fee" => $value["nake_fee"],
  2229. "cert_fee" => $value["cert_fee"],
  2230. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2231. "num" => $bidinfo["num"],
  2232. ];
  2233. if ($value['is_gold_price'] == 1) {
  2234. $price = GoldPrice($god, $budget / 100);
  2235. $value['sale_price'] = round($price, 2);
  2236. }
  2237. $value['cost_fee'] = $value['origin_cost_fee'];
  2238. $value['specinfo'] = json_decode($value['specinfo'], true);
  2239. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2240. $value['bargain_status'] = $bidinfo['bargain_status'];
  2241. //reject驳回原因,status==5表示驳回
  2242. $value['reject'] = [];
  2243. if ($value['status'] >= 5) {
  2244. $value['reject'] = Db::name('bargain_order')
  2245. ->field('id,remark,status')
  2246. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2247. ->whereIn('status', [3, 8, 11])->order("id desc")
  2248. ->find();
  2249. }
  2250. //产地
  2251. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2252. if ($value['delivery_place'] != "") {
  2253. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2254. }
  2255. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2256. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2257. if ($value['origin_place'] != "") {
  2258. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2259. }
  2260. $value['origin_addr'] = GetAddr(json_encode($place));
  2261. // if($value['origin_place']!=''){
  2262. // $code = explode(",",$value['origin_place']);
  2263. // $temp=[];
  2264. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2265. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2266. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2267. // $addr= GetAddr(json_encode($temp));
  2268. // $value['origin_addr'] = $addr;
  2269. // }
  2270. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2271. $data[] = $value;
  2272. }
  2273. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2274. }
  2275. }